15

I am using the SQLite driver from http://code.google.com/p/sqlite-jdbc/wiki/Introduction Examples shown in the above doc shows how to connect an existing database.

In my application I need to create an SQLite database. How to do that? Is it sufficient to create a file with extension .db? Also is there a function called createFile(). If so how to use it? I googled and nobody is giving a clear answer.

1 Answer 1

39

SQLite creates new database file on first attempt to connect if file did not exist already.

So, simply use jdbc:sqlite:filename.db as JDBC connection string, and provided that you have permission to create filename.db, it will be created automatically. You can also manually pre-create this file with 0 size if you want.

Sign up to request clarification or add additional context in comments.

8 Comments

where is it created please?
It simply treats filename.db according to normal filename rules: in current process directory by default, or fully qualified path if file name starts with / (or \ on Windows).
Thanks in my case its in bin foldet in tomcat folder in program files I searched my computer@
Saving db in tomcat bin folder sounds like bad idea. It is very much possible that tomcat process will not have enough permissions to actually create your database file there. If it does, your application is likely to be vulnerable to some security exploit. If I were you, I would find better place for SQLite databases.
I'd just like to add for future readers, I kept getting the opening db: './filename.db': Access is denied message. I fixed it by giving my IDE administrator access on opening.
|

Your Answer

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.