修改为:if(rs.isLast())
{
}
else
{
}

解决方案 »

  1.   

    少了一句:
    Statement st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    另外:if (rs.last())是判断是什么呢?
    rs.last()作用是Moves the cursor to the last row in this ResultSet object.
      

  2.   

    sorry, 
    Statement st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    我写漏了!至于判断 rs.last() 我主要的目的是测试rs.last()是否执行。
    我觉得奇怪的是:系统既不打印OK也不打印flase?
      

  3.   

    catch (SQLException ex){
       //print info;
    System.out.println(ex.getMessage);//增加这行看看有什么异常
     }你的程序应该是没有执行到rs.last()处,
      

  4.   

    在打印前已经出错了
    你还是把SQLException抓一下
    看看是不是支持last()方法(很可能不支持)
      

  5.   

    //there are a few steps you have to do before you can run and test 
    //the following code, hope it will give a basic idea
    //the code below will use JDBC to connect to your data source 
    //read ALL the data inside and print out in you console window
    //IF YOU CAN GET THIS JOB DONE I THINK YOU WILL ABTAIN A LOT!!
    //step1
    //use microsoft Access to create a table named BOOKS.//step2
    //establish a data source naemed "BooksInfoODBC"(quote not include)
    //if you don't how to create a data source in you computer, 
    //check with your frieds//step 3
    //create a java class and run the following codeimport java.io.*;
    import java.sql.*;public class Test1 {
      public static void main(String[] args) {
        try {
          // loads the jdbc odbc bridge driver
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        }
        catch (ClassNotFoundException e) {
          System.err.println("Error" + e) ;
        }
        try {
          // establish db connection through a Connection object
          Connection con =  DriverManager.getConnection("jdbc:odbc:BooksInfoODBC") ;      // instance of a sql statement
          Statement stmt = con.createStatement();      // prepare sql statement
          String sqlStr = "SELECT * FROM BOOKS";      // execute the SELECT query through executeQuery()
          // save the result in ResultSet
          ResultSet rs = stmt.executeQuery(sqlStr);      // process the result of the ResultSet
          System.out.println(" the records selected are");
          ResultSetMetaData info = rs.getMetaData();      while (rs.next()) {
            for (int i=1; i<=info.getColumnCount(); i++) {
              System.out.print("\t" + rs.getString(i));
            }
            System.out.println();
          }      // close the ResultSet, Statement and Connection objects
          rs.close();
          stmt.close();
          con.close();
        }
        catch (SQLException e) {
          System.err.println("Error " + e);
        }
      }
    }