Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Navigationa with ResultSet

Navigationa with ResultSet

Scheduled Pinned Locked Moved Java
databasehelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chdboy
    wrote on last edited by
    #1

    I'm not able to move forward with the ResultSet with this code on "next Button". Here is the code

    public void nextrecord()
    {

    	Statement stmt = null;
        String query = "select \* from Employer";
        try {
        	
            stmt = con.createStatement(ResultSet.TYPE\_SCROLL\_INSENSITIVE,ResultSet.CONCUR\_READ\_ONLY);	        
             rs = stmt.executeQuery(query);
            
             if(rs.isBeforeFirst());
             {
             while(rs.next())
             {
    		
            firstNameTextField.setText(rs.getString(2));
        	lastNameTextField.setText(rs.getString(3));
        	addressTextField.setText(rs.getString(4));
        	
    	
             }
             
    }
             
        }
        catch (SQLException e )
        {
            e.printStackTrace();
        }
        
        }
    

    The problem is when I click on the next button ,it takes me to the last record and skips all the records ,I wanted to go through all the records one by one ,clicking each record one by one. There is one record present in the text fields before pressing next button.

    N 1 Reply Last reply
    0
    • C chdboy

      I'm not able to move forward with the ResultSet with this code on "next Button". Here is the code

      public void nextrecord()
      {

      	Statement stmt = null;
          String query = "select \* from Employer";
          try {
          	
              stmt = con.createStatement(ResultSet.TYPE\_SCROLL\_INSENSITIVE,ResultSet.CONCUR\_READ\_ONLY);	        
               rs = stmt.executeQuery(query);
              
               if(rs.isBeforeFirst());
               {
               while(rs.next())
               {
      		
              firstNameTextField.setText(rs.getString(2));
          	lastNameTextField.setText(rs.getString(3));
          	addressTextField.setText(rs.getString(4));
          	
      	
               }
               
      }
               
          }
          catch (SQLException e )
          {
              e.printStackTrace();
          }
          
          }
      

      The problem is when I click on the next button ,it takes me to the last record and skips all the records ,I wanted to go through all the records one by one ,clicking each record one by one. There is one record present in the text fields before pressing next button.

      N Offline
      N Offline
      Nagy Vilmos
      wrote on last edited by
      #2

      Separate your actions... 0. Method to query the data, then store the record set. 1. Method to display a record. Something like [untested code]

      class Hatstand
      extends Stuff
      {
      private RecordSet recordSet;
      // need to initialise & stuff.

      /**
      * Query the data
      */
      private void submitQuery()
      {
      Statement stmt = null;
      String query = "select * from Employer";
      try
      {
      stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
      this.recordSet = stmt.executeQuery(query);
      }
      catch (SQLException e )
      {
      // message box'd be better
      e.printStackTrace();
      this.recordSet = null;
      }
      finally
      {
      setRecord(true);
      }
      }

      /**
      * Set the displayed record
      * called after query and by next/previous buttons.
      */
      private void setRecord(boolean forward)
      {
      // set the record:
      boolean isNull = true;
      if (this.RecordSet != null)
      {
      if (forward && !this.RecordSet.isLast())
      {
      this.RecordSet.next();
      isNull = false;
      }
      else if (!forward && !this.RecordSet.isFirst())
      {
      this.RecordSet.previous();
      isNull = false;
      }
      }

      if (isNull)
      {
        firstNameTextField.setText(null);
        lastNameTextField.setText(null);
        addressTextField.setText(null);    }
      }
      else
      {
        firstNameTextField.setText(rs.getString(2));
        lastNameTextField.setText(rs.getString(3));
        addressTextField.setText(rs.getString(4));    }
      }
      

      }
      }

      speramus in juniperus

      C 1 Reply Last reply
      0
      • N Nagy Vilmos

        Separate your actions... 0. Method to query the data, then store the record set. 1. Method to display a record. Something like [untested code]

        class Hatstand
        extends Stuff
        {
        private RecordSet recordSet;
        // need to initialise & stuff.

        /**
        * Query the data
        */
        private void submitQuery()
        {
        Statement stmt = null;
        String query = "select * from Employer";
        try
        {
        stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
        this.recordSet = stmt.executeQuery(query);
        }
        catch (SQLException e )
        {
        // message box'd be better
        e.printStackTrace();
        this.recordSet = null;
        }
        finally
        {
        setRecord(true);
        }
        }

        /**
        * Set the displayed record
        * called after query and by next/previous buttons.
        */
        private void setRecord(boolean forward)
        {
        // set the record:
        boolean isNull = true;
        if (this.RecordSet != null)
        {
        if (forward && !this.RecordSet.isLast())
        {
        this.RecordSet.next();
        isNull = false;
        }
        else if (!forward && !this.RecordSet.isFirst())
        {
        this.RecordSet.previous();
        isNull = false;
        }
        }

        if (isNull)
        {
          firstNameTextField.setText(null);
          lastNameTextField.setText(null);
          addressTextField.setText(null);    }
        }
        else
        {
          firstNameTextField.setText(rs.getString(2));
          lastNameTextField.setText(rs.getString(3));
          addressTextField.setText(rs.getString(4));    }
        }
        

        }
        }

        speramus in juniperus

        C Offline
        C Offline
        chdboy
        wrote on last edited by
        #3

        Thanks for the Idea. :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups