Issue
I want to create some applications in Java netbeans using sqLite manager. i had done the following steps.
- I have done plugin to Mozilla Firefox a sqLite-manger database
- I have create database calling "mydb".
- I have create a table with 2 values fname , lname.
I got mydb.sqlite file.
In netbeans library i have add jar file calling sqlite-jdbc 3.7.2 jar
then i copy the file mydb.sqlite from the folder and paste into netbeans project folder .
- I want to connect with my project calling "test" in netbeans.
how to connect with netbeans application
Solution
Here is example http://www.tutorialspoint.com/sqlite/sqlite_java.htm
Most important part is jdbc url to create connection:
jdbc:sqlite:mydb.sqlite
This url assumes that test.db located in same directory, u application starts from. But u can put path to certain db.
For example:
jdbc:sqlite:c:/temp/sqlite/mydb.sqlite
If u distribute u application when there u manage some initialization. Actually u have to set environment for u application before start. Let's say u have good working application in netbeans and u copy application to another machine. Configure environment for application to make it same as actual working application instance in netbeans. Question u should think about
- What path to database to use relative or absolute?
- Where database location on filesystem (absolute path to database)?
- Where directory from which application starts (relative path to database)?
Useful information:
- jdbc driver will create database mysql.sqlite if it doesn't exists (path to directory "c:/temp/sqlite" should be real) and after u can recreate necessary structure of database.
- u can use System Properties https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html especially user.dir and user.home to set predefined location of u database (create database in there or copy existing database file)
Answered By - simar