jeudi 30 juillet 2015

Sqlite : java.sql.SQLException: attempt to write a readonly database

Code :

 try {
        Class.forName("org.sqlite.JDBC");

        String fname = jTextField1.getText();
        String lname = jTextField2.getText();
        String address = jTextField3.getText();
        String phone = jTextField4.getText();
        String position = jTextField5.getText();
        String salary = jTextField6.getText();
        Connection con = null;
        Statement st = null;
        int result = 0;


        con = DriverManager.getConnection("jdbc:sqlite:C:\\management.db");
        st = con.createStatement();
        if(fname != null && lname != null && address != null && phone != null && position != null && salary != null) {
            String instert = "insert into emp_details (firstname,lastname,address,phone,position,salary) VALUES('"+ fname +"','"+ lname +"','"+ address +"','"+ phone +"','"+ position +"','"+ salary +"') ";
            result = st.executeUpdate(instert);
            if(result == 1) {

                JOptionPane.showMessageDialog(this, "record successfully saved", "Emp Details", WIDTH);

                con.close();
            }
            else {
                JOptionPane.showMessageDialog(this, "Enter Correct Details", "Emp Details", WIDTH);
            }
        }
    } catch (ClassNotFoundException | SQLException ex) {
        Logger.getLogger(Emp.class.getName()).log(Level.SEVERE, null, ex);
    }

i made a program for Restaurant Management ..Whenever I try to add(insert) something to my database using my program, I get this exception:

"java.sql.SQLException: attempt to write a readonly database" .

Aucun commentaire:

Enregistrer un commentaire