我在使用sqlite连接到Java应用程序中的数据库时遇到了问题。
我已经将必需的jar文件(sqlite-jdbc-3.23.1.jar)导入了我的库。
每当我尝试设置并打开数据库路径时,都会收到以下消息:
Couldn't connect to database: [SQLITE_ERROR] SQL error or missing database (near "Info": syntax error)
这是到目前为止的代码:
public static final String DB_FILE = "clients.db"
public static final String DB_PATH = "jdbc:sqlite:C:/Users/Steven/Documents/ProjectAnnieMalsRemote/Databases/" + DB_NAME;
//Sets a connection to access and utilize sqlite expressions, which are assigned to the PreparedStatement variables for later use
private Connection conn;
public boolean open(){
try{
conn = DriverManager.getConnection(DB_PATH);
insertIntoClientInfo = conn.prepareStatement(ClientInfoTable.getInsertClientInfo());
insertIntoIncomeStatement = conn.prepareStatement(IncomeStatementTable.getInsertIncomeStatement());
return true;
} catch (SQLException e){
System.out.println("Couldn't connect to database: " + e.getMessage());
return false;
}
}
我尝试了此stack overflow thread的所有建议,但似乎没有一种解决方案有效。我也尝试过在路径名中将成对的斜杠更改为单斜杠,但还是没有运气。有什么建议吗?
答案 0 :(得分:0)
我实际上只是发现了问题所在。完成堆栈跟踪后,我发现正是这两行引起了问题
insertIntoClientInfo = conn.prepareStatement(ClientInfoTable.getInsertClientInfo());
insertIntoIncomeStatement = conn.prepareStatement(IncomeStatementTable.getInsertIncomeStatement());
因此,这与prepareStatement方法有关,该方法导致sqlite错误,并且连接本身没有问题。