如果你的JDBC驱动支持JDBC2.0,可以用rs.first()
public boolean first() throws SQLException
JDBC 2.0
Moves the cursor to the first row in the result set.
Returns:
true if the cursor is on a valid row; false if there are no rows in the result set
Throws: SQLException
if a database access error occurs or the result set type is TYPE_FORWARD_ONLY
public boolean first() throws SQLException
JDBC 2.0
Moves the cursor to the first row in the result set.
Returns:
true if the cursor is on a valid row; false if there are no rows in the result set
Throws: SQLException
if a database access error occurs or the result set type is TYPE_FORWARD_ONLY
解决方案 »
- 求一个组件上传EXCEL的问题
- 4年java经验,我该选择哪个?
- myeclipse中jsp调用servlet的路径问题
- 如何判断指定的url是否有效
- 求一个用jsp上传txt文档,导入sql server的范例
- 关于媒体播放的问题(jsp文件播放)
- ajax刷新内嵌页面后jquery获取不到form了 只在ie8中出现
- 我的TOMCAT是区分大小写的?如何不让他区分?
- 怎样自动检测用户有没有安装Adobe Reader的插件,并能自动安装它?
- jsp没人只好来这里讨教了!
- 在 jsp 中,取 cookie 的值只能一次 request.getCookies 全取出来,是不是?
- 请问为什么会出这个错:java.lang.OutOfMemoryError?
at sun.jdbc.odbc.JdbcOdbcResultSet.first(JdbcOdbcResultSet.java:2154)
at _jcfx._xshzmx_0right1__jsp._jspService(e:\Inetpub\wwwroot\shoulou\jcfx\xshzmx_right1.jsp:190)
at com.caucho.jsp.JavaPage.service(JavaPage.java:74)
at com.caucho.jsp.Page.subservice(Page.java:476)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:176)
at com.caucho.server.http.Invocation.service(Invocation.java:277)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:129)
at com.caucho.server.http.RunnerRequest.handleRequest(RunnerRequest.java:337)
at com.caucho.server.http.RunnerRequest.handleConnection(RunnerRequest.java:269)
at com.caucho.server.TcpConnection.run(TcpConnection.java:140)
at java.lang.Thread.run(Thread.java:484)
你的JDBC应该是JDBC1.1吧,升级为JDBC2.0就行了
然后在classpath指定位置行了。
不又到了第一条啦!省事!
{
DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
Connection conn =DriverManager.getConnection("jdbc:odbc:test","","");
Statement stmt=conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY); String strSQL = "select name,age from test"; //执行SQL语句并获取结果集
ResultSet rs = stmt.executeQuery(strSQL);
if(rs.next())
{
rs.last();
int totalRow=rs.getRow();
}
String[] str=new String[totalRow];
rs.beforeFirst();
int i=0;
while(rs.next())
{
str[i]=rs.getString("name");
i++;
}
for(int n=0;n<i;n++)
{
out.println(str[n]);
out.println("<br>");
}rs.close();
stmt.close();
conn.close();}
catch (Exception e) {}
ResultSet rs = stmt.executeQuery(strSQL);
if(rs.next())
{
rs.last();
int totalRow=rs.getRow();
}
rs.beforeFirst();
int i=0;
while(rs.next())
{
str[i]=rs.getString("name");
i++;
}
if(!rs.next())
while(rs.next()) 以后我要回到第一条,因为 while(rs.next()) 语句是在一个循环中,所以
不能再执行一遍 ResultSet rs=stmt.executeQuery(SQL);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
看看行不行
那你还要回到第一条数据?你说说你的思路啦!
我现在不理解你的思路,很难给你出熟主意啦!呵呵!!