Click here to Skip to main content
15,881,882 members
Home / Discussions / Java
   

Java

 
AnswerRe: Need help to simplify the solution Pin
Richard MacCutchan23-Jun-20 21:53
mveRichard MacCutchan23-Jun-20 21:53 
QuestionSSL Error erroneous? Pin
GenJerDan15-Jun-20 0:45
GenJerDan15-Jun-20 0:45 
Questiondiagram of gantt and java swing Pin
Member 1484673228-May-20 15:12
Member 1484673228-May-20 15:12 
QuestionBuying a computer for development in Java ecosystem Pin
Member 1484653628-May-20 7:55
Member 1484653628-May-20 7:55 
AnswerRe: Buying a computer for development in Java ecosystem Pin
Dave Kreskowiak28-May-20 15:54
mveDave Kreskowiak28-May-20 15:54 
AnswerRe: Buying a computer for development in Java ecosystem Pin
stonde202029-Jun-20 20:36
stonde202029-Jun-20 20:36 
AnswerRe: Buying a computer for development in Java ecosystem Pin
Sarbjit Grewal8-Sep-20 19:20
professionalSarbjit Grewal8-Sep-20 19:20 
Questionplz, someone should help me to debug this error my i can asses my database but my next button is not working with it it keep getting this error: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Employees.Workers.btnNextActio Pin
Member 1484280524-May-20 22:47
Member 1484280524-May-20 22:47 
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.Statement;  
import java.sql.DriverManager;
import javax.swing.JOptionPane;
public class Workers extends javax.swing.JFrame {

    Connection con;
    Statement stmt;
    ResultSet rs;
    
    
    /**
     * Creates new form Workers
     */
    public Workers() {
        initComponents();
        DoConnect();
    }
    
    public void DoConnect(){
       try{
           
        String host="jdbc:derby://localhost:1527/Employee";
        String uname= "Star";
        String uPass ="ST@r6738";
        
     
          Connection con=DriverManager.getConnection(host, uname, uPass);
          Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
          String SQL="SELECT * FROM WORKER";
          ResultSet rs=stmt.executeQuery(SQL);
          
          rs.next();
          int id_col =rs.getInt(1);
          String ID_=Integer.toString(id_col);
          String first_name=rs.getString("FIRST_NAME");
          String last_name=rs.getString("LAST_NAME");
          String job_title=rs.getString(4);
         
      textID.setText(ID_);
      textFirstname.setText(first_name);
      textLastName.setText(last_name);
      textJobTitle.setText(job_title);
          
          
       
      }
      
      catch(SQLException err){
        System.out.println(err.getMessage());
    }
}

    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        textFirstname = new javax.swing.JTextField();
        textID = new javax.swing.JTextField();
        textLastName = new javax.swing.JTextField();
        textJobTitle = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        btnFirst = new javax.swing.JButton();
        btnPrevious = new javax.swing.JButton();
        btnNext = new javax.swing.JButton();
        btnLast = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        textID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textIDActionPerformed(evt);
            }
        });

        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(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(textID, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(textFirstname, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(textLastName, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(3, 3, 3))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(textJobTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .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(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textJobTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(41, 41, 41))
        );

        btnFirst.setText("First");

        btnPrevious.setText("Previous");
        btnPrevious.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPreviousActionPerformed(evt);
            }
        });

        btnNext.setText("Next");
        btnNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNextActionPerformed(evt);
            }
        });

        btnLast.setText("Last");
        btnLast.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLastActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnFirst)
                .addGap(18, 18, 18)
                .addComponent(btnPrevious)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnNext)
                .addGap(18, 18, 18)
                .addComponent(btnLast)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnFirst)
                    .addComponent(btnPrevious)
                    .addComponent(btnNext)
                    .addComponent(btnLast))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(21, 21, 21))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(602, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    private void textIDActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
    }                                      

    private void btnNextActionPerformed(java.awt.event.ActionEvent evt) {                                        
      try{ 
             if (rs.next()){
          int id_col =rs.getInt("ID");
          String id=Integer.toString(id_col);
          String first_name=rs.getString("FIRST_NAME");
          String last_name=rs.getString("LAST_NAME");
          String job_title=rs.getString(4);
               
      textID.setText(id);
      textFirstname.setText(first_name);
      textLastName.setText(last_name);
      textJobTitle.setText(job_title);
             
   
             }
               

            else{
                rs.previous();
                JOptionPane.showMessageDialog(Workers.this, "End of file");
            }
      }
            catch(SQLException err){
                JOptionPane.showMessageDialog(this, err.getMessage());
               err.printStackTrace();
            }    
        
    }                                       

    private void btnPreviousActionPerformed(java.awt.event.ActionEvent evt) {                                            
         
    }                                           

    private void btnLastActionPerformed(java.awt.event.ActionEvent evt) {                                        



    }                                       

    /**
     * @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(Workers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Workers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Workers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Workers.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 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                   
}

AnswerRe: plz, someone should help me to debug this error my i can asses my database but my next button is not working with it it keep getting this error: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Employees.Workers.btnNextA Pin
Richard MacCutchan24-May-20 22:56
mveRichard MacCutchan24-May-20 22:56 
GeneralMessage Closed Pin
25-May-20 3:26
Member 1484309125-May-20 3:26 
GeneralRe: plz, someone should help me to debug this error my i can asses my database but my next button is not working with it it keep getting this error: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Employees.Workers.btnNextA Pin
Richard MacCutchan25-May-20 4:38
mveRichard MacCutchan25-May-20 4:38 
GeneralRe: plz, someone should help me to debug this error ... Pin
Richard Deeming27-May-20 1:08
mveRichard Deeming27-May-20 1:08 
GeneralRe: plz, someone should help me to debug this error ... Pin
Richard MacCutchan27-May-20 1:50
mveRichard MacCutchan27-May-20 1:50 
QuestionJava 1st Year Project Pin
Member 1483530117-May-20 18:12
Member 1483530117-May-20 18:12 
AnswerRe: Java 1st Year Project Pin
Richard MacCutchan17-May-20 21:05
mveRichard MacCutchan17-May-20 21:05 
QuestionReturn negative number as 0 Pin
and180y17-May-20 3:38
and180y17-May-20 3:38 
AnswerRe: Return negative number as 0 Pin
Richard MacCutchan17-May-20 5:38
mveRichard MacCutchan17-May-20 5:38 
GeneralRe: Return negative number as 0 Pin
and180y17-May-20 6:10
and180y17-May-20 6:10 
GeneralRe: Return negative number as 0 Pin
Richard MacCutchan17-May-20 6:47
mveRichard MacCutchan17-May-20 6:47 
GeneralRe: Return negative number as 0 Pin
and180y17-May-20 6:55
and180y17-May-20 6:55 
GeneralRe: Return negative number as 0 Pin
Richard MacCutchan17-May-20 21:02
mveRichard MacCutchan17-May-20 21:02 
GeneralRe: Return negative number as 0 Pin
and180y17-May-20 6:46
and180y17-May-20 6:46 
GeneralRe: Return negative number as 0 Pin
Richard Deeming18-May-20 0:55
mveRichard Deeming18-May-20 0:55 
GeneralRe: Return negative number as 0 Pin
and180y18-May-20 1:44
and180y18-May-20 1:44 
Questionhashing assignment Pin
Member 1483469916-May-20 20:43
Member 1483469916-May-20 20:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.