2

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
1
  • This looks ok to me, why do you think it is connecting to a database in memory? Commented Sep 12, 2012 at 9:55

2 Answers 2

4

You should have:

 String sDbUrl = "jdbc:sqlite:C:/path/to/myDB.db"; 
answered Sep 12, 2012 at 10:07
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.