mercredi 9 mars 2016

Null Pointer Exception Error connecting SQLite to Netbeans [duplicate]

This question already has an answer here:

I'm programming a login forum using a SQLite database connected to Netbeans. I have installed the sqlite connect jar file and installed it in the library. When i run this app howeveri keep getting a Null Pointer Exception Error. Any help would be appreciated.

import java.awt.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.*;

public class frmCustDirectLogin extends javax.swing.JFrame {

 Connection conn =null;
 ResultSet rs =null;
 PreparedStatement pst=null;
/**
 * Creates new form frmCustDirectLogin
 */
public frmCustDirectLogin() {
    initComponents();
    conn= ConnecttoDB.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 btnCustEnterActionPerformed(java.awt.event.ActionEvent evt) {                                             
    // TODO add your handling code here:
    String sql="select * from Employee_Info where username=? and password=?";
    try{
    pst=conn.prepareStatement(sql);
    pst.setString(1,txtCustUsername.getText());
    pst.setString(1,txtCustPassword.getText());

    rs=pst.executeQuery();
    if (rs.next()) {
        JOptionPane.showMessageDialog(null, "Username and Password is correct");

        EmployeeInfo s = new EmployeeInfo();
        s.setVisible(true);
    }

    else {
        JOptionPane.showMessageDialog(null, "Username and Password is not  correct");

    }
}

    catch(Exception e) 
    { 
       JOptionPane.showMessageDialog(null, e);



    }
}                             

Aucun commentaire:

Enregistrer un commentaire