SQLite database third-party Java extensions: http://www.zentus.com/sqlitejdbc/
There are 2 packages, one is nested (embedded) and the other is native (local ).
The difference is: Nested does not require additional DLL files, but it is slow. Native requires an additional DLL file, which is fast.
1. Use the nested package: sqlitejdbc-v037-nested.jar
Java code:
Java code
- Public class test {
- Public static void main (string [] ARGs) throws exception {
- // System. setproperty ("Java. Library. Path ",".");
- Class. forname ("org. SQLite. JDBC ");
- Connection conn = drivermanager. getconnection ("JDBC: SQLite: C:/test3.db ");
- // Establish a transaction mechanism, disable automatic submission, and set the rollback point
- Conn. setautocommit (false );
- Statement stat = conn. createstatement ();
- Stat.exe cuteupdate ("create table people (name, occupation );");
- Stat.exe cuteupdate ("insert into people values ('gandhi', 'politics ');");
- Stat.exe cuteupdate ("insert into people values ('turing', 'computers ');");
- Stat.exe cuteupdate ("insert into people values ('wittgenstein ', 'smartypants ');");
- Conn. Commit ();
- Resultset rs = stat.exe cutequery ("select * from people ;");
- While (Rs. Next ()){
- System. Out. println ("name =" + Rs. getstring ("name "));
- System. Out. println ("occupation =" + Rs. getstring ("Occupation "));
- }
- Rs. Close ();
- Conn. Close ();
- }
- }
2. Use native package: sqlitejdbc-v037-native.jar
In addition, a DLL file is required. If you directly place the DLL file in the bin directory of the JDK installation directory, no operation is required. The Java code is the same as the Java code using the nested package above.
If you do not place the DLL in the bin directory of the JDK installation directory but in a directory, you need to set a parameter:
For example:
Java code
- System. setproperty ("Java. Library. Path", "E:/1008/workspace/sqlitetest/sqlitejdbc. dll ");
Or
Java code
- System. setproperty ("Java. Library. Path", "E:/1008/workspace/sqlitetest /");
The rest of the code is the same. Reference URL: Workshop/
- Sqlitejdbc-v037-nested.jar (805.9 KB) Description: Nested package
- Sqlitejdbc-v037-Win-i386.rar (181.6 KB) Description: Native package and DLL file
4