我正在使用JDBC尝试从此表中进行选择:
CREATE TABLE PERIT (
COGNOM1 VARCHAR(30) NOT NULL,
COGNOM2 VARCHAR(30) NOT NULL,
DATANAIX DATE NOT NULL,
NOM VARCHAR(30) NOT NULL,
NIF VARCHAR(10) NOT NULL,
LOGIN VARCHAR(50) NOT NULL,
PASSWORDMD5 VARCHAR(50) NOT NULL,
NUMERO INT(3) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (NUMERO)
);
我想检查是否存在具有某个登录和PASSWORDMD5值的行,如下所示:
public int Login(String Login, String pass) {
Statement st = null;
ResultSet rs = null;
int count =0;
try {
st = con.createStatement();
String consulta = "Select count(*) from Perit p where p.LOGIN =";
consulta += Login;
consulta +=" and p.PASSWORDMD5 = MD5(";
consulta +=pass;
consulta+=")";
rs = st.executeQuery(consulta);
while (rs.next()) {
count = rs.getInt(1);
}
st.close();
rs.close();
} catch (SQLException ex) {
Logger.getLogger(JDBCMySQL.class.getName()).log(Level.SEVERE, null, ex);
}
return count;
}
但是当我调用 Login("LOGINPERIT1","PASSWORDMDPERIT") 时,我收到此错误:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)中sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)的'where子句'中的未知列'LOGINPERIT1'在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)at java.lang.reflect.Constructor.newInstance(Constructor.java:423)at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)at at com.mysql.jdbc.Util.getInstance(Util.java:408)在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:943)在com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)在com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)在com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)在com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680 )com的com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2497)com的com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2455) .mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1369)在info.infomila.info.JDBCMySQL.Login(JDBCMySQL.java:139)在info.infomila.info.ThreadHandler.run(ThreadHandler.java:56)