2
當我嘗試在使用java的SQLite中以編程方式創建數據庫時,它在控制檯中生成以下錯誤。SQLite:在「DATABASE」附近:語法錯誤
java.sql.SQLException: near "DATABASE": syntax error
at org.sqlite.DB.throwex(DB.java:288)
at org.sqlite.NativeDB.prepare(Native Method)
at org.sqlite.DB.prepare(DB.java:114)
at org.sqlite.PrepStmt.<init>(PrepStmt.java:37)
at org.sqlite.Conn.prepareStatement(Conn.java:224)
at org.sqlite.Conn.prepareStatement(Conn.java:217)
at org.sqlite.Conn.prepareStatement(Conn.java:206)
at com.mmcal.build.BuildDB.executeQuery(BuildDB.java:46)
at com.mmcal.build.BuildDB.createDB(BuildDB.java:19)
at MainGen.main(MainGen.java:16)
我的代碼是:
public class BuildDB {
Connection connection;
PreparedStatement ps;
ResultSet rs;
String qry;
public void createDB() {
qry = "CREATE DATABASE IF NOT EXISTS myDb";
executeQuery(qry);
}
public boolean executeQuery(String qry) {
int cnt = 0;
boolean flag = false;
connection = ConnectionMaster.connectDb();
try {
ps = connection.prepareStatement(qry);
cnt = ps.executeUpdate();
System.out.println(flag);
} catch (SQLException e) {
e.printStackTrace();
}
if (cnt == 0) {
flag = true;
}
return flag;
}
}
什麼在我的代碼的問題,或者這是通過編程SQLite中創建數據庫的正確方法是什麼?