日期:2014-05-19  浏览次数:20918 次

结合MySql数据库,用CachedRowSetImpl怎么取出数据?
public CachedRowSetImpl excuteQuery(String sql, SplitePage sp) {
System.out.println(sql);
// 语句对象
Statement stmt = null;
// 结果集对象
ResultSet rs = null;
try {
this.getConn();
// 获得语句对象
stmt = con.createStatement();
// 结果集对象赋值
rs = stmt.executeQuery(sql);
crs.populate(rs);
while (crs.next()) { //-----------------------------错误行
TestsPojo tp = new TestsPojo();
tp.setId(crs.getInt(1));
tp.setTname(crs.getString("tname"));
datas.add(tp);
tp = null;
}

} catch (Exception e) {
// TODO: handle exception
} finally{
DBConnection.closeResultSet(rs);
DBConnection.closeStatement(stmt);
DBConnection.closeCon(con);
}
return crs;
}

java.sql.SQLException: Invalid cursor position
at com.sun.rowset.CachedRowSetImpl.next(CachedRowSetImpl.java:1457)
at com.gecko.dao.TestsDAO.testsFindAll(TestsDAO.java:56)
at com.gecko.dao.TestsDAO.testFindAll(TestsDAO.java:77)
at com.gecko.manager.impl.TestManagerImpl.testsFindAll(TestManagerImpl.java:57)
at com.gecko.web.struts.actions.OpeaAction.selectForSplit(OpeaAction.java:91)
at com.gecko.web.struts.actions.OpeaAction.selectAll(OpeaAction.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)
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.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
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:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:667)
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)

在SqlServer2000中这样取数据没有问题,请问是不是mysql有特别的方法?
备注:可以添加,所以连接没有问题。



------解决方案--------------------
帮顶!