com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法中有错误;检查与您的MySQL服务器版本对应的手册,以便在'?'附近使用正确的语法在第1行获得此异常
private String selectCustDetail= "SELECT NAME, PASSWORD, RESID, ACTIVATED, USERTYPE FROM USERDETAIL WHERE MOBILENO=?";
ResultSet rs;
//PreparedStatement preparedStatement = null;
PreparedStatement preparedStatement = null ;
try {
// preparedStatement = con.prepareStatement(selectCustDetail);
preparedStatement = con.prepareStatement(selectCustDetail);
preparedStatement.setString(1, mobileno.toString().trim());
rs = preparedStatement.executeQuery(selectCustDetail );
while (rs.next()) {
// LOGGER.info("fetching - 1" + mobileno);
System.out.println(rs.getString("name"));
userDetai.setName(rs.getString("name"));
userDetai.setPassword(rs.getString("password"));
userDetai.setRestaurant(rs.getString("resId"));
userDetai.setActivated(rs.getString("activated"));
userDetai.setType(rs.getString("userType"));
// LOGGER.info("fetching - 2" + userDetai.getActivated());
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
//LOGGER.info("Exception - " + e.getMessage());
dinepostcons.msg = dinepostcons.dbError;
return false;
}
finally
{try {
if (preparedStatement != null) {
preparedStatement.close();
}
答案 0 :(得分:4)
更改
rs = preparedStatement.executeQuery(selectCustDetail );
到
rs = preparedStatement.executeQuery();
您希望使用绑定参数调用preparedStatement
的方法。不是来自Statement
的方法,它使String
没有绑定参数。