Connection conn = null;
ResultSet rs = null;
preparedStatement pss = null;
- //CallableStatement cstmt = null;
try
{
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" );
conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=master;Uid=sa;Pwd=1234;","sa","1234");
pss = conn.prepareStatement("SELECT SAVESERIALZEDDATA FROM SESSION.pINGSESSION3DATA WHERE SESSIONKEY = ?");
pss.setString(1,sessionKey);
rs = pss.executeQuery();
- //cstmt =conn.prepareCall("{CALL demoSp(? , ?)}") ;
while(rs.next()){
String name=rs.getString("name");
String pass = rs.getString(1) ; // 此方法比较高效
}
rs.close();
pss.close();
conn.close();
}
catch (Exception t)
{
// Insert Appropriate Error Handling Here
}
finally
{
// The finally clause is always executed - even in error
// conditions preparedStatements and Connections will always be closed
try
{
if (rs != null)
rs.close();
}
try
{
if (pss != null)
pss.close();
}
catch(Exception e) {}
try
{
if (conn != null)
conn.close();
}
catch (Exception e){}
}
}