lundi 3 août 2015

No such Table Sqlite JDBC

Yo guys. The problem I'm facing is pretty weird.. I am creating a table at first, then trying to put data on it, but for somereason something is ticking off. It says

[SQLITE_ERROR] SQL error or missing database (no such table: Name)

Aaand here's my basic code..

try{
                Class.forName("org.sqlite.JDBC");
                  conni  = DriverManager.getConnection("jdbc:sqlite://C://Users//Asus//Dropbox//TireShop.sqlite");


                  stmt = conni.createStatement();

                  String sql = "CREATE TABLE " + project.getText() + " (Id INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , Name TEXT, One TEXT, Two TEXT)";


                  stmt.executeUpdate(sql);
                  stmt.close();
                  conni.close();
            }catch (Exception e){
                System.err.println( e.getClass().getName() + ": " + e.getMessage() );
                  System.exit(0);

            }
            try{
                Class.forName("org.sqlite.JDBC");
                  conni  = DriverManager.getConnection("jdbc:sqlite://C://Users//Asus//Dropbox//TireShop.sqlite");

                  String query1 = "insert into Name (Name) values(?)";
                  PreparedStatement pst = conni.prepareStatement(query1);
                  pst.setString(1, project.getText());
                  pst.execute();
                  pst.close();
                  conni.close();
            }catch(Exception e){
                System.err.println( e.getClass().getName() + ": " + e.getMessage() );
                  System.exit(0);


            }
            try{
                Class.forName("org.sqlite.JDBC");
                  conni  = DriverManager.getConnection("jdbc:sqlite://C://Users//Asus//Dropbox//TireShop.sqlite");

                  String query1 = "insert into " + project.getText() + "(Name, One, Two) values(?,?,?)";
                  PreparedStatement pst = conni.prepareStatement(query1);
                  pst.setString(1, project.getText());
                  pst.setString(2, textField_one.getText());
                  pst.setString(3, textFieldtwo.getText());
                  pst.execute();
                  pst.close();
                  conni.close();
            }catch(Exception e){
                System.err.println( e.getClass().getName() + ": " + e.getMessage() );
                  System.exit(0);
            JOptionPane.showMessageDialog(null, "Thank you");

Thank you for the help! I really can understand... I guess the table is not being created at all, but it actually worked once. So It gets me even more confused o.o

Aucun commentaire:

Enregistrer un commentaire