我有一个servlet后续码 - 上运行SQL查询执行与PreparedStatement的
String loginID = request.getParameter("loginId").toString();
String loginPassword = request.getParameter("loginPassword").toString();
String strSQLcount = "SELECT COUNT(*) as 'Number Of Match' "
+ "FROM persons " + "WHERE (password =? AND id =?);";
PreparedStatement prepareSQL = connection
.prepareStatement(strSQLcount);
prepareSQL.setString(1, loginPassword);
prepareSQL.setString(2, loginID);
ResultSet numOfMatchResult = prepareSQL.executeQuery();
// now we know number of matchs ...
int numOfMatch = numOfMatchResult.getInt(1);
何时到达行int numOfMatch = numOfMatchResult.getInt(1);
它抛出异常 - java.sql.SQLException
。我查了一下,发现它是因为executeQuery()
没有找到。尽管我在用MySQL创建的persons
表中有两个字段 - id (text)
的值为“300”,password (text)
的值为“500”。当然我在loginID
和loginPassword
的两个值相同时检查它。我检查了与数据库连接的所有其他信息,因此我认为问题出在strSQLcount
的SQL语法中。
请显示异常消息/跟踪。请告诉您的代码是否曾经连接到特定的数据库。 – Javier 2012-08-05 08:39:02