com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column '?????' in 'where clause'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1026)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2465)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1383)
at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)
at com.db.DBBean.searchName(DBBean.java:186)
at com.juri.JuriFilter.doFilter(JuriFilter.java:43)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at com.login.LoginFilter.doFilter(LoginFilter.java:113)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)
已解决:是查询语句的语法不对,
执行HQL语句的时候报这个错 原因原来是在from User u where u.username = '"+username+"'
username两边忘加单引号
可能是用到了数据库里面保留的关键字作为了字段。
用的时候可以这样用 '关键字' 加上单引号。
String hql = new String("select u from User u where u.userName="+userName+" and u.psd="+psd);
修改为:String hql = new String("select u from User u where u.userName='"+userName+"' and u.psd='"+psd+"'");
例如:
----解决方案--------------------
"select id from id_list where name = "+name;
改为:
"select id from id_list where name = '"+name+"'";
------解决方案--------------------
("select id from id_list where name = '"+name+"'")
------解决方案--------------------
rs=stmt.executeQuery("select id from id_list where name = '"+name+"';"); // ....
------解决方案--------------------
你写的语句最后生成是
...where name = employee
而应该生成的是
...where name = ‘employee’
总之就是少了引号 所以把employee当作列而不是字符串对待了
------解决方案--------------------
int num=rs.getInt("id");
改为
if(rs.next()){
int num=rs.getInt("id");
}