当前位置: 代码迷 >> Java Web开发 >> [求助]JDBC滚动结果集问题!
  详细解决方案

[求助]JDBC滚动结果集问题!

热度:241   发布时间:2007-08-07 13:10:27.0
[求助]JDBC滚动结果集问题!

我在JSP中写到:(代码片断)

程序代码:

Connection conn = cgclass.getConn();
Statement stmt = conn.createStatemen(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = \"select distinct SELL_ORG_ID,SELLING_ORG_NAME,city,area_id from new_fmt_supplier order by city\";
ResultSet rs = stmt.executeQuery(sql);
pages=rs.getFetchSize()/20;


程序代码:

rs.absolute(row*20+1); 为什么这句话抛异常!(方法不支持,为什么不支持啊 我有设置滚动结果集啊)
for(int i=0;i<20;i++){
rs.next();
String SELL_ORG_ID = rs.getString(\"SELL_ORG_ID\").trim();
String SELL_ORG_NAME = rs.getString(\"SELLING_ORG_NAME\").trim();
String city = rs.getString(\"city\").trim();
String area_id = rs.getString(\"area_id\").trim();
something...
}


异常如下:
org.apache.jasper.JasperException: Sharenet.S331.ex.txt: Method not yet supported.
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:98)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:172)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
at java.lang.Thread.run(Thread.java:534)


[此贴子已经被作者于2007-8-7 13:11:42编辑过]

搜索更多相关主题的帖子: JDBC  滚动  结果  row  

----------------解决方案--------------------------------------------------------
这个问题貌似有前辈问过了,可以查查以前的帖子
----------------解决方案--------------------------------------------------------

看了下面一个示例可能对你有所帮助

conn.jsp
<%
String sDBDriver = "COM.ibm.db2.jdbc.app.DB2Driver";
String sConnStr = "jdbc:db2:faq";
Connection conn = null;
Statement stmt = null;
ResultSet rs=null;
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
out.print("faq(): " + e.getMessage());
}

try{
conn = DriverManager.getConnection(sConnStr,"wsdemo","wsdemo1");
stmt = conn.createStatement();
}catch(SQLException e){
out.print(e.toString());
}
%>

query.jsp

<%@ page language="java" import="java.sql.*" %>
<%@ page contentType="text/html; charset=gb2312" %>
<%@ include file="conn.jsp" %>
<%
.......
int pages=0;
int pagesize=10;
ResultSet result = null;
ResultSet rcount = null;

pages = new Integer(request.getParameter("pages")).intValue();

if (pages>0)
{

String sql=" state=´我不傻´";
int count=0;
try {
rcount = stmt.executeQuery("SELECT count(id) as id from user where "+sql);
catch(SQLException ex) {
out.print("aq.executeQuery: " + ex.getMessage());
}
if(rcount.next())
count = rcount.getInt("id");
rcount.close();

if (count>0)
{
sql="select * from user where "+sql;
try {
result = stmt.executeQuery(sql);
}
catch(SQLException ex) {
out.print("aq.executeQuery: " + ex.getMessage());
}

int i;
String name;
// result.first();
// result.absolute((pages-1)*pagesize);
// 此方法jdbc2.0支持。编译通过,但执行不过,不知是不是跟驱动有关,只好用下面的笨办法。
for(i=1;i<=(pages-1)*pagesize;i++)
result.next();
for(i=1;i<=pagesize;i++) {
if (result.next()) {
name=result.getString("name");
out.print(name);
}
result.close();
int n= (int)(count/pagesize);
if (n*pagesize<count) n++;
if (n>1)
{
for(i=1;i<=n;i++)
out.print("<a href=query.jsp?pages="+i+">"+i+" </a>");
}
}
}
%>


----------------解决方案--------------------------------------------------------
楼上大哥,能不能解释一下红色部分啊?看不大明白啊!
----------------解决方案--------------------------------------------------------
  相关解决方案