java.sql.SQLException: 調用中無效的參數這個錯誤是在結果集循環取出是拋出的。我不明白的是,用連接池才會拋出這個錯,用其它的連接就不會?在Weblogic中測試連接池也沒有問題。請問這是為什么?代碼在下面:
public boolean isLogin(String uid, String pwd) {
boolean isLogin = false;
Connection conn = this.getConnection();
if (conn != null) {
String sql =
"select username,pwd from wasuserinfor where userName=? and pwd=?";
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, uid);
ps.setString(2, pwd);
ResultSet rs = ps.getResultSet();
while (rs.next()) {
String userNaem = rs.getString("USERNAME");
String password = rs.getString("PWD");
isLogin = true;
}
}
catch (SQLException ex) {
ex.printStackTrace();
}
finally {
if (conn != null) {
try {
conn.close();
}
catch (SQLException ex1) {
ex1.printStackTrace();
}
}
}
}
return isLogin;
}
private Connection getConnection() {
Object obj = null;
try {
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("jdbc/oracle");
return ds.getConnection();
}
catch (SQLException ex) {
return null;
}
catch (NamingException ex) {
return null;
}
}
解決辦法是看了代碼:ResultSet rs = ps.getResultSet();
之前一個要先執行ps.executeQuery();這樣就不會有錯了。