com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
我用MySQL数据库,用JAVA进行查表操作,数据库连接正常,但是总是不能正常查询这是查询的代码publicintlogin(StringuserName,Stringp...
我用MySQL数据库,用JAVA进行查表操作,数据库连接正常,但是总是不能正常查询
这是查询的代码
public int login(String userName, String pwd) {
int i=0;
PreparedStatement ps=null;
ResultSet rs=null;
String sql="select * from t_student where userName=?,pwd=? ";
try{
Connection conn= DBConnection.getConn();
ps=conn.prepareStatement(sql);
ps.setString(1, userName);
ps.setString(2,pwd);
rs=ps.executeQuery();
while(rs.next()){
i=rs.getInt(1);
}
}catch(Exception e){
e.printStackTrace();
}
System.out.println();
return i;
}
}
下面是异常
username:admin
pwd:admin
get a connection!
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'pwd='admin'' at line 1
数据库连接时成功的,不知道是什么问题 展开
这是查询的代码
public int login(String userName, String pwd) {
int i=0;
PreparedStatement ps=null;
ResultSet rs=null;
String sql="select * from t_student where userName=?,pwd=? ";
try{
Connection conn= DBConnection.getConn();
ps=conn.prepareStatement(sql);
ps.setString(1, userName);
ps.setString(2,pwd);
rs=ps.executeQuery();
while(rs.next()){
i=rs.getInt(1);
}
}catch(Exception e){
e.printStackTrace();
}
System.out.println();
return i;
}
}
下面是异常
username:admin
pwd:admin
get a connection!
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'pwd='admin'' at line 1
数据库连接时成功的,不知道是什么问题 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询