dimanche 29 mars 2015

JDBC connects to SQLite database but SQLite.Exception:no such table

I am using SQLite for my database. I downloaded SQLite Manager and used this to create my database and tables. I then use the following code to connect to the database. The program connects to the database but when I try to exeute a SQL query I get this error: "java.sql.SQLException: SQLite.Exception: no such table: test"



//database connecting class
public class DBConnect {
Connection conn=null;

public static Connection connecrDb(){
try{
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:DataBaseU.sqlite");
System.out.println("connection success");
return conn;
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
return null;
}
}

}


code for main Form



Connection conn = null;
Statement stmt = null;
ResultSet rs =null;
PreparedStatement pst = null;
public MainForm() {
initComponents();
conn = DBConnect.connecrDb();

}


code for insert query in button



private void add_item_groupActionPerformed(java.awt.event.ActionEvent evt) {
try{
String sql ="insert into test(t) values(?)";
pst = conn.prepareStatement(sql);
pst.setString(1, txt_itemgp.getText());

pst.execute();
JOptionPane.showMessageDialog(null, "Saved ");
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}

Aucun commentaire:

Enregistrer un commentaire