0

I tried to make previous button to show data from database by sql library (java.sql.* ), so I have this exception java.sql.SQLException : ResultSet is TYPE_FORWARD_ONLY.

I done it by this code:

       private void b_previousActionPerformed(java.awt.event.ActionEvent evt) {                                           
        int i = this.page;
        while(i == this.page){
            try{
                if(conn.rs.previous()){
            conn.rs.previous();
            this.page = conn.rs.getInt("page");
            this.contact = conn.rs.getString("contact");
            show_quran.setText(this.contact);}
                else{
                    return;
                }
            }
            catch(Exception e){
            System.err.println(e.getClass().getName() + " : " + e.getMessage());
            }
        }    
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Abdullah
  • 1
  • 1
  • Take a look here [resultset-exception-set-type-is-type-forward-only-why](http://stackoverflow.com/questions/6367737/resultset-exception-set-type-is-type-forward-only-why) – Shashank Kadne Oct 19 '13 at 11:19
  • cherck the javadoc for [ResultSet](http://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html) to see how you can configure the cursor. – A4L Oct 19 '13 at 11:22
  • Post the code of statement and connection creation. – Maximin Oct 19 '13 at 11:25
  • This is the code for connection: public void db_connect(){ try{ Class.forName("org.sqlite.JDBC"); conn = DriverManager.getConnection("jdbc:sqlite:quran.db"); stmt = conn.createStatement(); System.out.println("^_^"); } catch(Exception e){ System.err.println(e.getClass().getName() + " : " + e.getMessage()); } } and this for stmt: conn.stmt = conn.conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); – Abdullah Oct 20 '13 at 08:00

1 Answers1

2

Because by default backward seeking is disabled in java. So to go previous you have to enable TYPE_SCROLL_SENSITIVE Detailed description of ResultSet types can be found here.

Try like this as example

Statement s = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs = s.executeQuery("your query here");

Then you can go for backward seek.

Maximin
  • 1,655
  • 1
  • 14
  • 32
  • Thanks @Maximin , I tried what you said, than I have now this exception: `java.sql.SQLException : SQLite only supports TYPE_FORWARD_ONLY cursors` – Abdullah Oct 19 '13 at 13:52
  • @Abdullah Because SQLite doesn't support backward seek. – Maximin Oct 21 '13 at 05:35