mercredi 23 mars 2016

How to execute sqlite query in Java?

I am having problem executing queries of sqlite database in Java. I want to create a new table in my database when the app starts. I am also getting a error saying "java.lang.nullPointerException"

Here is the code:

public class New_user {

private JFrame frame;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private JTextField textField_4;
private JTextField textField_5;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                New_user window = new New_user();
                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the application.
 */

Connection conn = null;
ResultSet rs = null;
PreparedStatement pst = null;

public New_user() {

    initialize();
    conn = sqliteConnection.ConnectorDB();
    OnstartCreateTable();
}

public void OnstartCreateTable(){
    String sql = "CREATE TABLE employee_info (emloyeeeid INTEGER PRIMARY KEY  NOT NULL , name CHAR, surname CHAR, age INTEGER, username CHAR, password CHAR);";
    try{
        pst = conn.prepareStatement(sql);
        rs=pst.executeQuery();


    }

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

}

Aucun commentaire:

Enregistrer un commentaire