I need to connect to a Sqlite database, I am using following code but I reckon it connects to a database in memory. how can I connect to a database on my disk.
String sDriver = "org.sqlite.JDBC";
String Database = "NyDatabase.sqlite";
String sJdbc = "jdbc:sqlite";
String sDbUrl = sJdbc + ":" + Database;
Class.forName(sDriver);
conn = DriverManager.getConnection(sDbUrl);
Statement st = conn.createStatement();
// result = st.executeQuery(Select).toString();
rs = st.executeQuery(Select);
while (rs.next()) {
for (int i = 1; i <= 4; i++)
result[i] = rs.getString(i);
}
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
catch(Exception e){
e.printStackTrace();
}
asked Sep 12, 2012 at 9:50
Eme Emertana
5718 gold badges14 silver badges30 bronze badges
-
This looks ok to me, why do you think it is connecting to a database in memory?Dutts– Dutts2012年09月12日 09:55:22 +00:00Commented Sep 12, 2012 at 9:55
2 Answers 2
You should have:
String sDbUrl = "jdbc:sqlite:C:/path/to/myDB.db";
answered Sep 12, 2012 at 10:07
LaGrandMere
10.4k1 gold badge37 silver badges42 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You have to use the correct JDBC URL to specify the database file.
See How to Specify Database Files in the documentation of the JDBC driver for SQLite (assuming that that's the JDBC driver you're using).
answered Sep 12, 2012 at 9:55
Jesper
208k47 gold badges325 silver badges361 bronze badges
Comments
default