com.microsoft.sqlserver.jdbc.SQLServerException: 没有为参数号 1 设置值。

信息:Serverstartupin5079mscom.microsoft.sqlserver.jdbc.SQLServerException:没有为参数号1设置值。at... 信息: Server startup in 5079 ms
com.microsoft.sqlserver.jdbc.SQLServerException: 没有为参数号 1 设置值。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildParamTypeDefinitions(SQLServerPreparedStatement.java:260)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildPreparedStrings(SQLServerPreparedStatement.java:219)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doPrepExec(SQLServerPreparedStatement.java:612)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:400)

at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:350)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:285)

at com.dao.loginDao.login(loginDao.java:28)
at com.servlet.LoginServlet.doPost(LoginServlet.java:54)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)

dao包
public Customer login(String userName,String Password){

Connection con=null;
PreparedStatement pst=null;
ResultSet rs=null;
Customer cut=null;
try {
String sql ="select * from Customer where username=? and password=?";
con=DBManager.getCon();
pst=con.prepareStatement(sql);
rs=pst.executeQuery();
System.out.println("有户名为"+userName);
pst.setString(1, userName);
pst.setString(2, Password);
rs = pst.executeQuery();
while(rs.next()){
String name=rs.getString("name");
String sex=rs.getString("sex");
String tel=rs.getString("tel");
String username=rs.getString("username");
String password=rs.getString("password");
cut=new Customer(name,sex,tel,username,password);
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{
try {
DBManager.close(rs, pst, con);
} catch (Exception e2) {
// TODO: handle exception
e2.printStackTrace();
}

}
return cut;
}
展开
 我来答
匿名用户
2017-08-18
展开全部
ps = ct.prepareStatement("select username,nserPasswd from users where users.username=? and users.userPasswd=?");

//执行
rs = ps.executeQuery();

你创建的PreparedStatement对象,然后呢SQL语句中的2个?的值你还没注入进去呢就去数据库执行了
所以报错了
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式