首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

100分求救 [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]必须声明变量 '@P1'请大家帮帮啊呀

2012-03-13 
100分求救 [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]必须声明变量 @P1请大家帮帮啊??急

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.base.BaseStatement.executeQuery(Unknown Source)


at com.hz.dbconnection.DBConnect.executeQuery(DBConnect.java:144)
at com.hz.receivefile.ReceivefileDao.getOneReceivefile(ReceivefileDao.java:107)
at com.hz.struts.action.ReceivefileAction.execute(ReceivefileAction.java:70)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
解决了:




把访问数据库语句改了即可以了:
String sql_getOnefile = "SELECT * FROM RECEIVEFILE WHERE RECEIVEID="+rid_int;
完整代码:
/**
* 获得单个收文信息
* @param String rid
* @author zcg
* @return ReceivefileForm
* @throws Exception 
*/ 
public ReceivefileForm getOneReceivefile(String rid) throws Exception
{
int rid_int = Integer.parseInt(rid);
ReceivefileForm rf_getone=new ReceivefileForm();
DBConnect db_getOnefile = new DBConnect();
ResultSet rs = null;
String sql_getOnefile = "SELECT * FROM RECEIVEFILE WHERE RECEIVEID="+rid_int;
//System.out.println("sql_getOnefile::::::::"+sql_getOnefile);
try
{
db_getOnefile = new DBConnect(sql_getOnefile);
rs = db_getOnefile.executeQuery(sql_getOnefile);
if(rs.next())
{
rf_getone.setReceiveid(rs.getInt("RECEIVEID")+"");
rf_getone.setReceivetitle(rs.getString("RECEIVETITLE"));
rf_getone.setReceivedate(rs.getString("RECEIVEDATE"));
rf_getone.setReceivetype(rs.getString("RECEIVETYPE"));
rf_getone.setReceivesource(rs.getString("RECEIVESOURCE"));
}
rs.close();
db_getOnefile.close();
}catch(Exception e)
{
e.printStackTrace();
}

return rf_getone;

}
[解决办法]
估计SQL语句没写好
[解决办法]
估计是sql出错,你看看你的每个字段有不有为空的,再看看数据库有不有为空的!
[解决办法]
各位大侠我也是呀.帮帮我吧.我是刚学做网站用的是jsp和sqlserver2000.下面是报错信息java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Underlying
input stream returned zero bytes
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)


at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseData.getString(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.getString(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.getString(Unknown Source)
at _jsp._user_0news__jsp._jspService(user_news.jsp:92)
at com.caucho.jsp.JavaPage.service(JavaPage.java:60)
at com.caucho.jsp.Page.pageservice(Page.java:570)
at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:175)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:178)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
at com.caucho.server.hmux.HmuxRequest.handleRequest(HmuxRequest.java:419)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:389)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:507)
at com.caucho.util.ThreadPool.run(ThreadPool.java:433)
at java.lang.Thread.run(Thread.java:534)


--------------------------------------------
Resin-3.0.19 (built Mon, 15 May 2006 04:50:47 PDT)

热点排行