Results 1 to 2 of 2

Thread: Some Trouble

  1. #1
    Alunage is offline Member
    Join Date
    Apr 2014
    Posts
    1
    Rep Power
    0

    Default Some Trouble

    Keep getting a "This method should only be called on ResultSet objects that are scrollable (type TYPE_SCROLL_INSENSITIVE)."

    Java Code:
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import javax.swing.JOptionPane;
    public class NewJFrame2 extends javax.swing.JFrame {
        Connection con;
        Statement stmt;
        ResultSet rs;
        public static String userSNO=null,userPass=null;
        private PreparedStatement preparedStatement;
        public NewJFrame2() {
            initComponents();
            DoConnect();            
        }
        public void DoConnect( ) {
        try {
        String host = "jdbc:derby://localhost:1527/FINALIA";
        String uName = "joel";
        String uPass = "joel";
        Connection con = DriverManager.getConnection( host, uName, uPass );
        stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE );
    
        String SQL = "SELECT * FROM PASSWORD";
    
        rs=stmt.executeQuery(SQL);
        rs.next();
        }
        catch ( SQLException err ) {
        System.out.println( err.getMessage( ) );
        }
        }
        
        public boolean loginPrivilegeCheck(){
        boolean loginPrivilege = false;
        try {
        String host = "jdbc:derby://localhost:1527/FINALIA";
        String uName = "joel";
        String uPass = "joel";
        Connection con = DriverManager.getConnection( host, uName, uPass );
        stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE );
        preparedStatement = con.prepareStatement("SELECT * FROM JOEL.PASSWORD WHERE SNO=? AND PASSWORD=? AND USERLEVEL=1");
        preparedStatement.setString(1, userSNO); 
        preparedStatement.setString(2, userPass);
        
        
        
        rs = preparedStatement.executeQuery();
        if (rs.next()) {
        loginPrivilege=false;
        } else {
        loginPrivilege=true;
        }
        } catch ( SQLException err ) {
        System.out.println( err.getMessage( ) );
        }
        return loginPrivilege;
        }       
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jTextField1 = new javax.swing.JTextField();
            jTextField2 = new javax.swing.JTextField();
            jTextField3 = new javax.swing.JTextField();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            jButton3 = new javax.swing.JButton();
            jButton4 = new javax.swing.JButton();
            jButton5 = new javax.swing.JButton();
            jButton6 = new javax.swing.JButton();
            jButton7 = new javax.swing.JButton();
            jButton8 = new javax.swing.JButton();
            jButton9 = new javax.swing.JButton();
            jButton10 = new javax.swing.JButton();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowActivated(java.awt.event.WindowEvent evt) {
                    formWindowActivated(evt);
                }
            });
    
            jLabel1.setText("SNO");
    
            jLabel2.setText("PASSWORD");
    
            jLabel3.setText("ACCESS LEVEL");
    
            jButton1.setText("NEXT");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
    
            jButton2.setText("PREVIOUS");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
                }
            });
    
            jButton3.setText("FIRST");
            jButton3.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton3ActionPerformed(evt);
                }
            });
    
            jButton4.setText("LAST");
            jButton4.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton4ActionPerformed(evt);
                }
            });
    
            jButton5.setText("ADD");
            jButton5.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton5ActionPerformed(evt);
                }
            });
    
            jButton6.setText("UPDATE");
            jButton6.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton6ActionPerformed(evt);
                }
            });
    
            jButton7.setText("EDIT");
            jButton7.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton7ActionPerformed(evt);
                }
            });
    
            jButton8.setText("CANCEL");
            jButton8.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton8ActionPerformed(evt);
                }
            });
    
            jButton9.setText("DELETE");
    
            jButton10.setText("SAVE");
            jButton10.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton10ActionPerformed(evt);
                }
            });
    
            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)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel1)
                                    .addGap(54, 54, 54)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addGap(18, 18, 18)
                                    .addComponent(jTextField2))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel3)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jTextField3)))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGap(54, 54, 54))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jButton5)
                            .addGap(18, 18, 18)
                            .addComponent(jButton7)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jButton9)
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jButton6)
                            .addGap(18, 18, 18)
                            .addComponent(jButton8)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jButton10)
                            .addGap(0, 0, Short.MAX_VALUE))))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(26, 26, 26)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton1))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton2))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel3)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton3)))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jButton4)
                    .addGap(44, 44, 44)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton5)
                        .addComponent(jButton7)
                        .addComponent(jButton9))
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton6)
                        .addComponent(jButton8)
                        .addComponent(jButton10))
                    .addContainerGap(56, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>                        
    
        private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
         jTextField1.setEnabled(true);
         jTextField2.setEnabled(true);
         jTextField3.setEnabled(true);
         jButton8.setEnabled(true);
         jButton10.setEnabled(true);
         }                                        
    
        private void formWindowActivated(java.awt.event.WindowEvent evt) {                                     
            jTextField1.setEnabled(false);
            jTextField2.setEnabled(false);
            jTextField3.setEnabled(false);
            //DISABLED IF NOT ADMIN//
            jButton5.setEnabled(false); // add 
            jButton6.setEnabled(false); // update 
            jButton7.setEnabled(false); // edit 
            jButton8.setEnabled(false); // cancel
            jButton9.setEnabled(false); // delete
            jButton10.setEnabled(false); // save
            boolean privilegeCheck=loginPrivilegeCheck();{
            if(privilegeCheck==true)
            {
            jButton5.setEnabled(true);  
            jButton7.setEnabled(true);  
            jButton9.setEnabled(true); 
            
            
            }
            }    
            
                
            
           
        }                                    
    
        private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            jButton6.setEnabled(false); 
            jButton8.setEnabled(false); 
            jButton10.setEnabled(false);
            jTextField1.setEnabled(false);
            jTextField2.setEnabled(false);
            jTextField3.setEnabled(false);
    
        }                                        
    
        private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {                                          
            try {
                rs.moveToInsertRow( );
                rs.updateString("SNO", jTextField1.getText());
                rs.updateString("PASSWORD", jTextField2.getText());
                rs.updateString("USERLEVEL", jTextField3.getText());
                rs.insertRow( );
    
                stmt.close( );
                rs.close( );
                DoConnect();
                }
                catch ( SQLException err ) {
                System.out.println( err.getMessage( ) );
                }
        }                                         
    
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            try {
    
            if ( rs.next( ) ) {
            String SNO=rs.getString("SNO");
            String P=rs.getString("PASSWORD");
            String USER=rs.getString("USERLEVEL");
            
    
            jTextField1.setText(SNO);
            jTextField2.setText(P);
            jTextField3.setText(USER);
            
    
            }
            else {
            rs.previous( );
                JOptionPane.showMessageDialog(NewJFrame2.this, "End of File");
            }//end of else
            }
            catch (SQLException err) {
                JOptionPane.showMessageDialog(NewJFrame2.this, err.getMessage());
    }
        }                                        
    
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            try {
    
            if ( rs.previous( ) ) {
            String SNO=rs.getString("SNO");
            String P=rs.getString("PASSWORD");
            String USER=rs.getString("USERLEVEL");
            
    
            jTextField1.setText(SNO);
            jTextField2.setText(P);
            jTextField3.setText(USER);
            
    
            }
            else {
            rs.next( );
                JOptionPane.showMessageDialog(NewJFrame2.this, "End of File");
            }//end of else
            }
            catch (SQLException err) {
                JOptionPane.showMessageDialog(NewJFrame2.this, err.getMessage());
    }
        }                                        
    
        private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            try {
    
            rs.first();
            String SNO=rs.getString("SNO");
            String P=rs.getString("PASSWORD");
            String USER=rs.getString("USERLEVEL");
            
    
            jTextField1.setText(SNO);
            jTextField2.setText(P);
            jTextField3.setText(USER);
            
    
            }
           
            catch (SQLException err) {
                JOptionPane.showMessageDialog(NewJFrame2.this, err.getMessage());
    }
        }                                        
    
        private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            try {
    
            rs.last();
            String SNO=rs.getString("SNO");
            String P=rs.getString("PASSWORD");
            String USER=rs.getString("USERLEVEL");
            
    
            jTextField1.setText(SNO);
            jTextField2.setText(P);
            jTextField3.setText(USER);
            
    
            }
           
            catch (SQLException err) {
                JOptionPane.showMessageDialog(NewJFrame2.this, err.getMessage());
    }
        }                                        
    
        private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            jTextField1.setEnabled(true);
            jTextField2.setEnabled(true);
            jTextField3.setEnabled(true);
            jButton6.setEnabled(true); 
            jButton8.setEnabled(true); 
            jButton10.setEnabled(true);
            jTextField1.setRequestFocusEnabled(true); 
        }                                        
    
        private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            try { 
            rs.updateString( "SNO",jTextField1.getText());
            rs.updateString( "PASSWORD", jTextField2.getText());
            rs.updateInt( "ID", Integer.parseInt(jTextField3.getText()));
            rs.updateRow( );
            JOptionPane.showMessageDialog(NewJFrame2.this, "Updated");
            }
            catch (SQLException err) {
            System.out.println(err.getMessage() );
            }
        }                                        
        
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            
            
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
    
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame2().setVisible(true);
                }
            });
        }
    
        // Variables declaration - do not modify                     
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton10;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton3;
        private javax.swing.JButton jButton4;
        private javax.swing.JButton jButton5;
        private javax.swing.JButton jButton6;
        private javax.swing.JButton jButton7;
        private javax.swing.JButton jButton8;
        private javax.swing.JButton jButton9;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        public static javax.swing.JTextField jTextField1;
        public static javax.swing.JTextField jTextField2;
        public static javax.swing.JTextField jTextField3;
        // End of variables declaration                   
    }

    If i remove the
    Java Code:
    public bollean login
    and keep the
    Java Code:
    public void DoConnect()
    it goes away, how do you keep the two methods without getting an error?
    PS:sorry for the bad english.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Some Trouble

    When posting about an exception when running your code you should post the full stack trace and highlight the line in your code from which the exception is thrown.

    Since you seem to be holding onto your ResultSet after querying the database, I'm first off going to say that that's not good practice. You should be turning that data into a Model that represents the results. You seem to be reusing the same ResultSet variable for more than one query as well, which is possibly the cause of your current troubles.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Having trouble with first GUI
    By Zexanima in forum New To Java
    Replies: 2
    Last Post: 10-01-2011, 02:23 PM
  2. Io trouble need help
    By loopsnhoops in forum New To Java
    Replies: 18
    Last Post: 06-03-2011, 03:35 AM
  3. Having trouble with IO
    By loopsnhoops in forum New To Java
    Replies: 0
    Last Post: 06-02-2011, 04:06 AM
  4. Im having trouble with.......
    By Java Noobie in forum New To Java
    Replies: 1
    Last Post: 03-12-2011, 05:06 PM
  5. Here comes trouble... :-)
    By sargehendricks in forum Introductions
    Replies: 1
    Last Post: 04-23-2009, 03:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •