mqnoy

[JAVA] how to connect sqlite3 on java

Nov 29th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. /****[SOURCE CODE]*****/
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4.  
  5. public class SQLiteJDBC {
  6.   public static void main( String args[] ) {
  7.       Connection c = null;
  8.      
  9.       try {
  10.          Class.forName("org.sqlite.JDBC");
  11.          c = DriverManager.getConnection("jdbc:sqlite:$lokasidb");// $lokasidb = lokasi database ex : /home/qnoy/sqlite_folder/testqq.db
  12.       } catch ( Exception e ) {
  13.          System.err.println( e.getClass().getName() + ": " + e.getMessage() );
  14.          System.exit(0);
  15.       }
  16.       System.out.println("Opened database successfully");
  17.    }
  18. }
  19.  
  20. tested with :
  21. sqlite3 :  3.21.0
  22. java : openjdk version 1.8.0_151
  23.  
  24. codding with :
  25. BlueJ : v4.1.2
  26.  
  27.  
  28.  
  29. REF :
  30. http://www.sqlitetutorial.net/sqlite-java/sqlite-jdbc-driver/
  31. https://www.tutorialspoint.com/sqlite/sqlite_java.htm
  32. https://bitbucket.org/xerial/sqlite-jdbc/downloads/
Advertisement
Add Comment
Please, Sign In to add comment