java简单的数据库操作为什么一直出现语法错误? 跪求高手解答
关键代码如下
public boolean login(String account,String password){
boolean b = false;
String sql = "select * from user where account=? and password=?";
conn = DBUtil.getDBUtil().getConnection();
try {
ps = conn.prepareStatement(sql);
ps.setString(1, account);
ps.setString(2, password);
ResultSet rs = ps.executeQuery();
if(rs!=null&&rs.next()){
System.out.println("从sqlserver数据库中查询到的数据"+rs.getString(2));
return true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return b;
}
最后我写了一个main还是进行测试,出现如下错误:
数据库连接成功
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]在关键字 'user' 附近有语法错误。
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source)
at com.xiaojiang.server.dao.UserDAO.login(UserDAO.java:25)
at com.xiaojiang.server.dao.DBUtil.main(DBUtil.java:54)
其中测试的main函数是这么写的:
public static void main(String[] args){
dbUtil = getDBUtil();
Connection conn = dbUtil.getConnection();
if(conn!=null){
System.out.println("数据库连接成功");
}
UserDAO userDao = new UserDAO();
userDao.login("6742323895", "jdssdsj824");
}
检查的N遍一直查找不出来,求各位大神帮帮小弟!!!