The ResultSet interface provides getXXX methods for retrieving column values from the current row. Values can be retrieved using either the index number of the column or the name of the column. In general, using the column index will be more efficient. Columns are numbered from 1. For maximum portability, result set columns within each row should be read in left-to-right order, and each column should be read only once.
ResultSet rs = stmt.executeQuery("SELECT * FROM TABLEname");加参数“ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE”试试
首先,若使用odbc数据源访问数据库,理论上而言无论什么数据库,以及你是否设定Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
(即结果集支持滚动光标),应该都是要按顺序的,因为数据源访问产生的结果集是不支持滚动的。
其次,若使用jdbc驱动访问数据库,则大多是支持滚动的,只要你设定了Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
就行,因为对于各种不同的数据库,大多的驱动都支持滚动光标。
另外,还有既不使用odbc,也不是使用jdbc驱动访问数据库的方式,这个我不大了解,故无法说明。
应该是数据库的原因
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://yourServer;DatabaseName=dbname","user","pass"); //Statement st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
Statement st = con.createStatement(); ResultSet res = st.executeQuery("select id,name,desc from table"); while (res.next())
System.out.println(res.getDouble("desc")+res.getString("name")+res.getInt("id") +"\n"; con.close();
}
catch (Exception ex)
{
e.printStackTrace();}