I have been having problems connecting to a database in my java application using sqlite.
I have already imported the jar file necessary (sqlite-jdbc-3.23.1.jar) into my libraries.
Whenever I try to set and open the path to the database, I receive the following message:
Couldn't connect to database: [SQLITE_ERROR] SQL error or missing database (near "Info": syntax error)
Here is what the code looks like so far:
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;
}
}
I have tried all suggestions from this stack overflow thread , but none of the solutions seem to work. I have also tried changing the paired slashes to single slashes in the path name, but still no luck. Any suggestions?
I actually just found out what the problem was. After doing a stack trace, I found that it was these two lines which were causing the problem
insertIntoClientInfo = conn.prepareStatement(ClientInfoTable.getInsertClientInfo());
insertIntoIncomeStatement = conn.prepareStatement(IncomeStatementTable.getInsertIncomeStatement());
So it was something to do with the prepareStatement methods that were causing a sqlite error and there was no problem with the connection itself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.