【发布时间】:2017-11-19 13:04:29
【问题描述】:
public static LoginBean logIn(String userName)throw Exception{
String query="select user_name, password from login where user_name="+userName;
System.out.println(query);
Statement st=null;
ResultSet result=null;
LoginBean bean=new LoginBean();
try{
st=con.createStatement();
result=st.executeQuery(query);
while(result.next()){
bean.setUserName(result.getString("user_name"));
bean.setPassword(result.getString("password"));
}
return bean;
}
finally
{
if(result!=null)
{
result.close();
}
if(st!=null)
{
st.close();
}
}
}
我正在执行此方法,但它给了我错误,即com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'admin' in 'where clause' 我检查了语法但找不到错误。
【问题讨论】:
-
“我已经检查了语法” - 你有吗?您能否在问题中包含您尝试执行的 SQL 查询的实际运行时值?告诉我们您已经检查过它并且您认为它是正确的与向我们展示它以便我们可以检查它是不同的。