title: Database scrolling buttons using java forms - Error when calling next method to move cursor up Resultset object
body: <p>Basically: I am adding four buttons to a java form. The buttons will enable me to move forward through the records, move back, move to the last record, and move to the first record.</p>
  
  <p>I am using netbeans IDE 7.2.1 together with the inbuilt Apache Derby Network Server.</p>
  
  <p>I am trying to scroll through my database records and output results in text fields. Initially the constructor successfully connects to the database and loads the first row from the result set object using the next() method to move the cursor. All fine and dandy, but then when I try to initiate the next record to load by pressing the next button on the form and thereby calling the next event method I get an error message: the code seems top get stuck at the point when I try to call the next() method again!
  Any Help would be appreciated.</p>
  
  <p>Here is my java form source code:</p>
  
  <pre><code>package Employer;
  
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.SQLException;
  import java.sql.Statement;
  import java.sql.ResultSet;
  import javax.swing.JOptionPane;
  
  public class Workers extends javax.swing.JFrame {
  
      Connection con;
      Statement stmt;
      ResultSet rs;
  
      public Workers() {
          initComponents();
          DoConnect();
      }
  
      public void DoConnect( ) {
  
          try{
          String host = "jdbc:derby://localhost:1527/Employer";
          String uName = "admins";
          String uPass= "admins";
  
  
          Connection con = DriverManager.getConnection( host, uName, uPass );
  //        Statement stmt = con.createStatement( );
          stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE );
  
          String SQL = "SELECT * FROM WORKERS";
          ResultSet rs = stmt.executeQuery( SQL );
  
          rs.next( );
          int id_col = rs.getInt("ID");
          String id=Integer.toString(id_col);
          String first= rs.getString("First_Name");
          String last = rs.getString("Last_Name");
          String job = rs.getString("Job_Title");
  
          textID.setText(id);
          textFirstName.setText(first);
          textLastName.setText(last);
          textJobTitle.setText(job);
  
          }
  
          catch ( SQLException err ){
                 System.out.println( err.getMessage( ) );
  
          }
  
      }
  
      @SuppressWarnings("unchecked")
      // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;                          
      private void initComponents() {
  
          jPanel1 = new javax.swing.JPanel();
          textJobTitle = new javax.swing.JTextField();
          jLabel1 = new javax.swing.JLabel();
          textID = new javax.swing.JTextField();
          textFirstName = new javax.swing.JTextField();
          textLastName = new javax.swing.JTextField();
          jPanel2 = new javax.swing.JPanel();
          btnNext = new javax.swing.JButton();
          btnLast = new javax.swing.JButton();
          btnPrevious = new javax.swing.JButton();
          btnFirst = new javax.swing.JButton();
  
          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  
          textJobTitle.setToolTipText("");
          textJobTitle.setName(""); // NOI18N
  
          jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
          jLabel1.setText("Job Title:");
  
          javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
          jPanel1.setLayout(jPanel1Layout);
          jPanel1Layout.setHorizontalGroup(
              jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jPanel1Layout.createSequentialGroup()
                  .addContainerGap()
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addComponent(jLabel1)
                      .addComponent(textID, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 127, Short.MAX_VALUE)
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                      .addGroup(jPanel1Layout.createSequentialGroup()
                          .addComponent(textFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                          .addComponent(textLastName, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                      .addComponent(textJobTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)))
          );
          jPanel1Layout.setVerticalGroup(
              jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jPanel1Layout.createSequentialGroup()
                  .addContainerGap()
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(textID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(textFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(textLastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addGap(24, 24, 24)
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(jLabel1)
                      .addComponent(textJobTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addContainerGap(55, Short.MAX_VALUE))
          );
  
          textJobTitle.getAccessibleContext().setAccessibleName("");
  
          btnNext.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
          btnNext.setText("Next");
          btnNext.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  btnNextActionPerformed(evt);
              }
          });
  
          btnLast.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
          btnLast.setText("Last");
  
          btnPrevious.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
          btnPrevious.setText("Previous");
  
          btnFirst.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
          btnFirst.setText("First");
  
          javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
          jPanel2.setLayout(jPanel2Layout);
          jPanel2Layout.setHorizontalGroup(
              jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                  .addContainerGap()
                  .addComponent(btnFirst)
                  .addGap(29, 29, 29)
                  .addComponent(btnPrevious)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 59, Short.MAX_VALUE)
                  .addComponent(btnNext)
                  .addGap(33, 33, 33)
                  .addComponent(btnLast)
                  .addContainerGap())
          );
          jPanel2Layout.setVerticalGroup(
              jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jPanel2Layout.createSequentialGroup()
                  .addGap(27, 27, 27)
                  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(btnNext)
                      .addComponent(btnLast)
                      .addComponent(btnPrevious)
                      .addComponent(btnFirst))
                  .addContainerGap(29, Short.MAX_VALUE))
          );
  
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
          getContentPane().setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addContainerGap()
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addContainerGap(795, Short.MAX_VALUE))
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addGap(22, 22, 22)
                  .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addGap(72, 72, 72)
                  .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addContainerGap(78, Short.MAX_VALUE))
          );
  
          pack();
      }// &lt;/editor-fold&gt;                        
  
      private void btnNextActionPerformed(java.awt.event.ActionEvent evt) {                                        
          // TODO add your handling code here:
          try {
  
  
  
  
  
          if ( rs.next( )) {
  
                 int id_col = rs.getInt("ID");
                  String id = Integer.toString(id_col);
                  String first = rs.getString("First_Name");
                  String last = rs.getString("Last_Name");
                  String job = rs.getString("Job_Title");
  
                  textID.setText(id);
                  textFirstName.setText(first);
                  textLastName.setText(last);
                 textJobTitle.setText(job);
              }
              else {
                  rs.previous( );
                  JOptionPane.showMessageDialog(Workers.this, "End of File");
              }
          }
          catch (SQLException err) {
              JOptionPane.showMessageDialog(Workers.this, err.getMessage());
              System.out.println( err.getMessage( ) );
          }
      }                                       
  
  
      public static void main(String args[]) {
  
          java.awt.EventQueue.invokeLater(new Runnable() {
              public void run() {
                  new Workers().setVisible(true);
              }
          });
      }
      // Variables declaration - do not modify                     
      private javax.swing.JButton btnFirst;
      private javax.swing.JButton btnLast;
      private javax.swing.JButton btnNext;
      private javax.swing.JButton btnPrevious;
      private javax.swing.JLabel jLabel1;
      private javax.swing.JPanel jPanel1;
      private javax.swing.JPanel jPanel2;
      private javax.swing.JTextField textFirstName;
      private javax.swing.JTextField textID;
      private javax.swing.JTextField textJobTitle;
      private javax.swing.JTextField textLastName;
      // End of variables declaration                   
  </code></pre>
  
  <p>And here are the error messages that I get from the Stack trace console window:</p>
  
  <blockquote>
    <p>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
      at Employer.Workers.btnNextActionPerformed(Workers.java:211)    at
    Employer.Workers.access$000(Workers.java:12)  at
    Employer.Workers$1.actionPerformed(Workers.java:139)  at
    javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
      at
    javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
      at
    javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
      at
    javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
      at
    javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
      at java.awt.Component.processMouseEvent(Component.java:6505)    at
    javax.swing.JComponent.processMouseEvent(JComponent.java:3321)    at
    java.awt.Component.processEvent(Component.java:6270)  at
    java.awt.Container.processEvent(Container.java:2229)  at
    java.awt.Component.dispatchEventImpl(Component.java:4861)     at
    java.awt.Container.dispatchEventImpl(Container.java:2287)     at
    java.awt.Component.dispatchEvent(Component.java:4687)     at
    java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
      at
    java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
      at java.awt.Container.dispatchEventImpl(Container.java:2273)    at
    java.awt.Window.dispatchEventImpl(Window.java:2719)   at
    java.awt.Component.dispatchEvent(Component.java:4687)     at
    java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)    at
    java.awt.EventQueue.access$200(EventQueue.java:103)   at
    java.awt.EventQueue$3.run(EventQueue.java:682)    at
    java.awt.EventQueue$3.run(EventQueue.java:680)    at
    java.security.AccessController.doPrivileged(Native Method)    at
    java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
      at
    java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
      at java.awt.EventQueue$4.run(EventQueue.java:696)   at
    java.awt.EventQueue$4.run(EventQueue.java:694)    at
    java.security.AccessController.doPrivileged(Native Method)    at
    java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)   at
    java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
      at
    java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
      at
    java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
      at
    java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
      at
    java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
    BUILD SUCCESSFUL (total time: 18 seconds)</p>
  </blockquote>
  
  <p>Thank you.</p>