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();这样就不会有错了。