Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Last week, we had the author of
TDD for a Shopping Website LiveProject
. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See
for the agenda and registration link
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Paul Clapham
Ron McLeod
Jeanne Boyarsky
Tim Cooke
Sheriffs:
Liutauras Vilda
paul wheaton
Henry Wong
Saloon Keepers:
Tim Moores
Tim Holloway
Stephan van Hulst
Carey Brown
Frits Walraven
Bartenders:
Piet Souris
Himai Minh
Forum:
Swing / AWT / SWT
java lang NullPointerException
james kinyua
Greenhorn
Posts: 28
1
posted 6 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hae, i have a problem saving data in the database, am getting NullPointerException.
below are three
java
files for my code
import java.sql.*; import javax.swing.JOptionPane; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author jeam */ public class log extends javax.swing.JFrame { /** * Creates new form log */ Connection conn = null; ResultSet rs = null; PreparedStatement pst = null; public log() { initComponents(); conn = jconnect.connecrDb(); } /** * 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(); txt_username = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); txt_password = new javax.swing.JPasswordField(); jLabel1 = new javax.swing.JLabel(); cmd_login = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jPanel1.setBackground(new java.awt.Color(0, 204, 0)); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Login", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Stencil", 1, 24))); // NOI18N jLabel2.setText("password"); jLabel1.setText("username"); cmd_login.setText("Login"); cmd_login.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmd_loginActionPerformed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(161, 161, 161) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel1) .addComponent(jLabel2)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txt_username, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txt_password, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(90, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(cmd_login) .addGap(137, 137, 137)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(txt_username, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(txt_password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(cmd_login) .addGap(7, 7, 7)) ); 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.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(34, 34, 34) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(130, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void cmd_loginActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: String sql = "select* from users where username=? and password =?"; try{ pst = conn.prepareStatement(sql); pst.setString(1, txt_username.getText()); pst.setString(2, txt_password.getText()); rs=pst.executeQuery(); if(rs.next()){ vehiclet vt = new vehiclet(); vt.setVisible(true); } else { JOptionPane.showMessageDialog(null, "incorrect username/password"); } } catch(Exception e){ JOptionPane.showMessageDialog(null, e); } } /** * @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(log.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(log.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(log.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(log.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 log().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton cmd_login; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JPanel jPanel1; private javax.swing.JPasswordField txt_password; private javax.swing.JTextField txt_username; // End of variables declaration } [code=java] [code=java] import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import javax.swing.*; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author jeam */ public class vehiclet extends javax.swing.JFrame { /** * Creates new form vehiclet */ Connection conn=null; ; ResultSet rs = null; PreparedStatement pst = null; public vehiclet() { initComponents(); } /** * 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(); jLabel11 = new javax.swing.JLabel(); r2t2 = new javax.swing.JTextField(); fw1 = new javax.swing.JTextField(); fw3 = new javax.swing.JTextField(); jLabel10 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); r3t1 = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); r2t1 = new javax.swing.JTextField(); fw2 = new javax.swing.JTextField(); txt_runs = new javax.swing.JTextField(); r3t2 = new javax.swing.JTextField(); jLabel8 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); r1t2 = new javax.swing.JTextField(); r1t1 = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel(); combo_vehicle = new javax.swing.JComboBox(); cmd_save = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jToolBar1 = new javax.swing.JToolBar(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenuItem1 = new javax.swing.JMenuItem(); jSeparator1 = new javax.swing.JPopupMenu.Separator(); jMenuItem2 = new javax.swing.JMenuItem(); jSeparator2 = new javax.swing.JPopupMenu.Separator(); jMenuItem3 = new javax.swing.JMenuItem(); jMenu2 = new javax.swing.JMenu(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jPanel1.setBackground(new java.awt.Color(0, 102, 102)); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Vehicle Turnabout Monitoring Sheet", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Stencil", 1, 18), new java.awt.Color(0, 204, 51))); // NOI18N jLabel11.setForeground(new java.awt.Color(0, 255, 153)); jLabel11.setText("Enter factory weight for run 3"); jLabel10.setForeground(new java.awt.Color(0, 204, 153)); jLabel10.setText("Enter factory weight for run 2"); jLabel2.setForeground(new java.awt.Color(0, 153, 102)); jLabel2.setText("Enter number of runs"); jLabel5.setForeground(new java.awt.Color(0, 204, 153)); jLabel5.setText("Enter time out for run 2"); jLabel3.setForeground(new java.awt.Color(0, 204, 153)); jLabel3.setText("Enter time out for run 1"); jLabel8.setForeground(new java.awt.Color(0, 255, 153)); jLabel8.setText("Enter time in for run 3"); jLabel4.setForeground(new java.awt.Color(0, 204, 153)); jLabel4.setText("Enter time in for run 1"); jLabel6.setBackground(new java.awt.Color(51, 255, 153)); jLabel6.setForeground(new java.awt.Color(0, 255, 153)); jLabel6.setText("Enter time in for run 2"); jLabel7.setForeground(new java.awt.Color(0, 204, 153)); jLabel7.setText("Enter time out for run 3"); jLabel9.setBackground(new java.awt.Color(51, 51, 0)); jLabel9.setForeground(new java.awt.Color(0, 204, 153)); jLabel9.setText("Enter factory weight for run 1"); jLabel1.setBackground(new java.awt.Color(204, 204, 204)); jLabel1.setForeground(new java.awt.Color(51, 255, 51)); jLabel1.setText("Choose Vehicle "); combo_vehicle.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "KBW 028L", "KBM 092B", "KAV 966Q", "KBW 029L", "KAT 338U", "KAT 256U", "KBT 727Q", "KBG 142E", " " })); combo_vehicle.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { combo_vehicleActionPerformed(evt); } }); 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(jLabel2) .addComponent(jLabel1) .addComponent(jLabel3) .addComponent(jLabel4) .addComponent(jLabel11) .addComponent(jLabel10) .addComponent(jLabel9) .addComponent(jLabel8) .addComponent(jLabel7) .addComponent(jLabel6) .addComponent(jLabel5)) .addGap(24, 24, 24) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(r2t1) .addComponent(r2t2) .addComponent(r1t2) .addComponent(fw2) .addComponent(r3t1) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(combo_vehicle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 191, Short.MAX_VALUE)) .addComponent(r3t2) .addComponent(fw3) .addComponent(fw1) .addComponent(r1t1) .addComponent(txt_runs)) .addContainerGap()) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(combo_vehicle, 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(jLabel2) .addComponent(txt_runs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(r1t1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(r1t2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel9) .addComponent(fw1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(6, 6, 6) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5) .addComponent(r2t1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6) .addComponent(r2t2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel10) .addComponent(fw2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(10, 10, 10) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel7) .addComponent(r3t1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel8) .addComponent(r3t2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel11) .addComponent(fw3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); cmd_save.setText("Save"); cmd_save.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmd_saveActionPerformed(evt); } }); jButton2.setText("Cancle"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jToolBar1.setBackground(new java.awt.Color(0, 51, 51)); jToolBar1.setRollover(true); jMenuBar1.setBackground(new java.awt.Color(0, 153, 153)); jMenuBar1.setBorder(null); jMenu1.setText("File"); jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK)); jMenuItem1.setText("New"); jMenu1.add(jMenuItem1); jMenu1.add(jSeparator1); jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK)); jMenuItem2.setText("Save"); jMenu1.add(jMenuItem2); jMenu1.add(jSeparator2); jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK)); jMenuItem3.setText("Exit"); jMenuItem3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem3ActionPerformed(evt); } }); jMenu1.add(jMenuItem3); jMenuBar1.add(jMenu1); jMenu2.setBackground(new java.awt.Color(0, 102, 102)); jMenu2.setText("Edit"); jMenuBar1.add(jMenu2); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGap(190, 190, 190) .addComponent(cmd_save) .addGap(37, 37, 37) .addComponent(jButton2) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(4, 4, 4) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cmd_save) .addComponent(jButton2)) .addContainerGap(29, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: System.exit(0); } private void combo_vehicleActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void cmd_saveActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try{ String sql = "Insert into vehiclet(vehicle,runs,r1t1,r1t2,fw1,r2t1,r2t2,fw2,r3t1,r3t2,fw3) " + "values(?,?,?,?,?,?,?,?,?,?,?)"; //String sql ="insert into users(username,password) values(?,?)"; pst = conn.prepareStatement(sql); String value = combo_vehicle.getSelectedItem().toString(); pst.setString(1, value); pst.setString(2, txt_runs.getText()); pst.setString(3, r1t1.getText()); pst.setString(4, r1t2.getText()); pst.setString(5, fw1.getText()); pst.setString(6, r2t1.getText()); pst.setString(7, r2t2.getText()); pst.setString(8, fw2.getText()); pst.setString(9, r3t1.getText()); pst.setString(10, r3t2.getText()); pst.setString(11, fw3.getText()); pst.executeQuery(); JOptionPane.showMessageDialog(null,"saved"); } catch(Exception e){ JOptionPane.showMessageDialog(null, e); /* private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: System.exit(0); } */ }} /** * @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(vehiclet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(vehiclet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(vehiclet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(vehiclet.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 vehiclet().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton cmd_save; private javax.swing.JComboBox combo_vehicle; private javax.swing.JTextField fw1; private javax.swing.JTextField fw2; private javax.swing.JTextField fw3; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JMenuItem jMenuItem3; private javax.swing.JPanel jPanel1; private javax.swing.JPopupMenu.Separator jSeparator1; private javax.swing.JPopupMenu.Separator jSeparator2; private javax.swing.JToolBar jToolBar1; private javax.swing.JTextField r1t1; private javax.swing.JTextField r1t2; private javax.swing.JTextField r2t1; private javax.swing.JTextField r2t2; private javax.swing.JTextField r3t1; private javax.swing.JTextField r3t2; private javax.swing.JTextField txt_runs; // End of variables declaration }
import java.sql.*; import javax.swing.*; public class jconnect { Connection conn = null; public static Connection connecrDb() { try{ Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/logindemo?" + "user=root&password="); //JOptionPane.showMessageDialog(null, "connection established"); return conn; } catch (Exception e) { JOptionPane.showMessageDialog(null, e); return null; } } }
Dave Tolls
Rancher
Posts: 4801
50
posted 6 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Can you post the full stack trace, as well as highlight the line in your code that the NullPointerException is thrown from?
Trawling through 100s of lines of code trying to spot a potential NPE is like looking for a needle in a haystack.
Are we home yet? Wait, did we forget the tiny ad?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Fingerprint Verification in java
JFrame
How to add JTable into a JPanel
report creating
Pressing a button to open a new window
More...