日期:2014-05-17  浏览次数:20670 次

mysql执行异常问题
下面是在程序中执行SQL语句时的异常~~~~
请问怎么回事啊?

非常感谢~~~~~~

Java code

public JuriBean searchName(String name)  //name就是下表中的employee
{
    JuriBean jb=new JuriBean();
    Connection conn=null;
    Statement stmt=null;
    ResultSet rs=null;
    try {
        conn=getConnection();
        stmt=conn.createStatement();
        rs=stmt.executeQuery("select id from id_list where name = "+name);  //这里抛出异常,异常如下
        int num=rs.getInt("id");
    } catch (SQLException e) {            
                e.printStackTrace();
    }
    finally
    {
        closeConnection(conn); //自己实现的关闭方法,没有问题!
        closeStatement(stmt);
        closeResultSet(rs);
    }
    return jb;
}




com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'employee' 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)


表id_list:

id name password
01 employee 12345


再次感谢~~~~~

------解决方案--------------------
"select id from id_list where name = "+name;
改为:
"select id from id_list where name = '"+name+"'";
------解决方案--------------------
("select id from id_list wh