100分求救 [Microsoft][
SQLServer 2000 Driver for JDBC][SQLServer]必须声明变量 '@P1'请大家帮帮啊??急呀...
上面的错误是我在java连sql中用PreparedStatement预处理做时发生的
我的java代码:
pstmt = conn.prepareStatement( " " +
"insert into UserInfo( " +
"userid, " +
"username, " +
"userpassword, " +
"useremail, " +
"usertruename, " +
"usercodeid, " +
"userposacalcode, " +
"usersex, " +
"usersheng, " +
"usercity, " +
"userxian, " +
"userphone, " +
"usermobile, " +
"userjianjie) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?) ");
/*
* 计算出递增的用户ID
*/
++idNumber;
pstmt.setInt(1,idNumber);
pstmt.setString(2,userinfo.getUserName());
pstmt.setString(3,userinfo.getUserPassWord());
pstmt.setString(4,userinfo.getUserEmail());
pstmt.setString(5,userinfo.getUserRealName());
pstmt.setString(6,userinfo.getUserShengFenCode());
pstmt.setString(7,userinfo.getUserPocal());
pstmt.setString(8,userinfo.getUserSex());
pstmt.setString(9,userinfo.getSheng());
pstmt.setString(10,userinfo.getCity());
pstmt.setString(11,userinfo.getXian());
pstmt.setString(12,userinfo.getTel());
pstmt.setString(13,userinfo.getMobilePhone());
pstmt.setString(14,userinfo.getDescription());
请各们兄弟帮帮啊
------解决方案--------------------你测试一下,是不是数据库连接没有连接正确,你的这个SQL写的没有什么问题,看看是不是不能获得连接.
------解决方案--------------------把這個SQL連起來寫。注意空格。你這麽寫是多此一舉。此外++idNumber是嚴重錯誤的,id應該在
數據庫端自增,你這個程序要是是多用戶環境肯定出錯。
------解决方案--------------------可现在还是报那个错,把数据库中的ID改成自增的了已经,一般是哪的原因?我测试了一下,下面的代码能成功执行: pstmt = conn.prepareStatement( "select * from test ");
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
System.out.println( "rs.getString(1) = " + rs.getString(1)); //这里不要取2次
那为什么还出现这个错误?请多指教啊??
------解决方案--------------------你是用的桥连接还是驱动连接?如果是桥连接,检查一下你的连接的默认数据库是不是正确的?
------解决方案--------------------知道怎么解决了没 ,我也遇到了这样的错误了,麻烦大大们告诉个
------解决方案--------------------我也出现这个问题:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]必须声明变量 '@P1'。
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.tds.TDSCursorRequest.openCursor(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.execute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
at com.microsoft.jdbc.