I am trying to run two queries, one to create a table and another to insert some value in it. Table is getting created but value is not getting added to the table.
stmt = c.createStatement();
//Creating the Database if not Already Present
String sql = "CREATE TABLE if not exists senti "
+ "( latitude double NULL, "
+ "longitude double NULL, "
+ "Sentiment varchar(30) NULL) ";
stmt.executeUpdate(sql);
stmt.close();
//System.out.println(count + "count");
stmt1 = c.createStatement();
String sql1 = "INSERT INTO senti values(25.62010856,85.13277482,'neutral')";
stmt1.executeUpdate(sql1)
Apparently you've called
c.setAutoCommit(false)
... but then you haven't committed the update. So no, that won't have updated the database. Just use
c.commit();
after the update - or turn auto-commit back on instead. If you were expecting the table not to be created until you called commit()
, basically DDL statements can't be rolled back so you shouldn't try to include those within a larger transaction.
See more on this question at Stackoverflow