错误是
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'em_accouts' 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:3515)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2477)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1422)
at com.tool.JDBConnection.executeQuery(JDBConnection.java:58)
at com.dao.TestDao.main(TestDao.java:18)
代码如下 jsp+servlet+javabean
JDBConnection connection = null;
connection = new JDBConnection();
connection.creatConnection(); //利用构造方法调用类中的对象对数据库创建连接
EmployeeVO em = new EmployeeVO();
String sql = "select * from tb_employee where em_accouts='" +"123"+
"'";
ResultSet rs = connection.executeQuery(sql);
if(rs!=null){
try {
System.out.println("abx");
while (rs.next())
{
em.setEm_id(Integer.valueOf(rs.getString(1))); //取得数据库流水号信息
em.setEm_number(rs.getString(2)); //取得员工的编号信息
em.setEm_accouts(rs.getString(3)); //取得员工的账号信息
em.setEm_password(rs.getString(4)); //取得员工的密码信息
em.setEm_name(rs.getString(5)); //取得员工的姓名信息
em.setEm_sex(rs.getString(6)); //取得员工性别信息
em.setEm_age(Integer.valueOf(rs.getString(7))); //取得员工的年龄信息
em.setEm_birthday(rs.getString(8)); //取得员工出生日期
em.setEm_business(rs.getString(9)); //取得员工职务信息
em.setEm_school(rs.getString(10)); //取得员工的毕业学校信息
connection.closeConnection();
}
}
catch (SQLException ex) {
}}
可是将sql语句直接输入到mysql中是没有问题的 不知道该怎么解决了?
--转自