当前位置: 技术问答>java相关
这个jdbc代码错在哪里?
来源: 互联网 发布时间:2015-02-28
本文导语: import java.io.*; import java.sql.*; class query { public static void main(String args[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(ClassNotFoundException ce) { System.out.println("dd"); } try { Connection con=DriverManager.getConnection(...
import java.io.*;
import java.sql.*;
class query
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ce)
{
System.out.println("dd");
}
try
{
Connection con=DriverManager.getConnection("jdbc:odbc:pipe","est2","est2");
System.out.println("ok");
Statement stm=con.createStatement();
ResultSet rs=stm.executeQuery("select id from adder where id=1");
while (rs.previous())
{
System.out.println(rs.getString("id"));
}
stm.close();
con.close();
}
catch(SQLException e)
{
System.out.println(e.getMessage());
}
}
}
编译没有问题,但是执行时报错:Result set type is TYPE_FORWARD_ONLY,为什么啊?
import java.sql.*;
class query
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ce)
{
System.out.println("dd");
}
try
{
Connection con=DriverManager.getConnection("jdbc:odbc:pipe","est2","est2");
System.out.println("ok");
Statement stm=con.createStatement();
ResultSet rs=stm.executeQuery("select id from adder where id=1");
while (rs.previous())
{
System.out.println(rs.getString("id"));
}
stm.close();
con.close();
}
catch(SQLException e)
{
System.out.println(e.getMessage());
}
}
}
编译没有问题,但是执行时报错:Result set type is TYPE_FORWARD_ONLY,为什么啊?
|
先搜索一下query.class,然后删掉,重新编译一下,看看是不是还是这个错误,
当然要用next()!
当然要用next()!