I am trying to create the table through java string but it is displaying error as table doesn't exist but when I run the same query directly on workbench it runs fine. Below is my code
String url = "jdbc:mysql://localhost:3306/" ;
String dbname = "tweetmap";
String username = "root";
String password = "root";
try
{
// SQL Driver needed for connecting to Database
Class.forName("com.mysql.jdbc.Driver");
c = DriverManager.getConnection(url+dbname,username,password);
c.setAutoCommit(true);
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 TEXT NULL) ";
stmt.executeUpdate(sql);
if(sentiment != null){
stmt1 = c.createStatement();
stmt1.executeUpdate("INSERT INTO `senti`(latitude,longitude,Sentiment) VALUE ('"+lati+"','"+longi+"','"+sentiment+"')");
}
}
catch(Exception e){
e.printStackTrace();
}
primary keyfor the table &remove IF NOT EXISTSclause from the query. Try the same.