问题描述
异常信息:java.sql.SQLException:[Microsoft][SQLServer2000DriverforJDBC]InvalidcallStatementmethod:{0}atcom.microsoft.jdbc.base.BaseExceptions.createException(UnknownSource)atcom.microsoft.jdbc.base.BaseExceptions.getException(UnknownSource)atcom.microsoft.jdbc.base.BasePreparedStatement.executeQuery(UnknownSource)atcom.wsy.newBeanBO.getnewsBean(newBeanBO.java:18)atcom.wsy.servlet.newServlet.doGet(newServlet.java:34)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:689)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:802)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)atcom.wsy.Filter.ModifyCode.doFilter(ModifyCode.java:23)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)atorg.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)atorg.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)atorg.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)atorg.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)部分代码:处理与news表业务逻辑:(我的代码是这样写的)publicnewsBeangetnewsBean(Stringsql){newsBeannb=newnewsBean();try{cn=newconnsqlserver().getConnection();ps=cn.prepareStatement("select*fromtb_newswhereid=?");ps.setString(1,sql);rs=ps.executeQuery(sql);if(rs.next()){//放入nbnb.setId(rs.getInt("1"));nb.setTitle(rs.getString("2"));nb.setContent(rs.getString("3"));nb.setAuthor(rs.getString("4"));nb.setSubmittime(rs.getString("5"));}}catch(Exceptione){e.printStackTrace();}finally{this.close();}returnnb;}连接数据库部分代码是这样处理的:publicConnectiongetConnection(){try{Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");cn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_net","sa","");System.out.println("连接成功");//Statementsmt=cn.createStatement();}catch(Exceptione){e.printStackTrace();}returncn;}publicResultSetexecuteQuery(Stringsql){if(cn==null)cn=getConnection();try{returncn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE).executeQuery(sql);}catch(Exceptione){e.printStackTrace();returnnull;}finally{}},请高手帮我看看哪里出了问题,怎么改正
解决方案
解决方案二:
ps=cn.prepareStatement("select*fromtb_newswhereid=?");ps.setString(1,sql);rs=ps.executeQuery(sql);这三句是不是有些问题啊?你的sql不就是"select*fromtb_newswhereid=?"?只需传递个id的值就行了。首先,你的方法里传递的sql是什么?如果是个id的值。那么我想你出错的原因应该是这句。直接调用:rs=ps.executeQuery();。如果是个子查询语句,那也一样rs=ps.executeQuery();你试试吧。
解决方案三:
该回复于2011-03-11 16:21:58被版主删除