mercredi 30 décembre 2015

Unable to create/modify sqlite tables from Java application

I have a basic java application and a sqlite DB. I can create table manually through sqLite browser. And I am able to access these tables from my JAVA application.

E.g. Reading from existing table: (I have omitted the try catch blocks in the sample below just to reduce the length of question)

PreparedStatement preparedStatement = null;
ResultSet resultSet = null;

String query = "select * from test1 where uname = ? and name = user1";
preparedStatement = connection.prepareStatement(query);
preparedStatement.setString(1, "test"); 
resultSet = preparedStatement.executeQuery();           

if(resultSet.next())
    return true;
else
    return false;

I am able to perform this query successfully.

However, if I create / modify a table, changes does not show up in SQlite DB (I am viewing db in sqLite browser). If I copy paste the same query in SQlite browser, the query runs successfully and a row is added.

PreparedStatement preparedStatement = null;
ResultSet resultSet = null;

String query = "INSERT INTO COMPANY (ID,NAME,AGE) VALUES (3, 'tOM', 32);";

preparedStatement = connection.prepareStatement(query); 
preparedStatement.executeUpdate();          

Am I missing something?

EDIT: Both the above tables exist in my sqlite db. Both were created through sqlite browser

Aucun commentaire:

Enregistrer un commentaire