Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
java_introduction [2015/06/09 13:59]
Joel Dare [Compiled]
java_introduction [2015/06/09 14:03]
Joel Dare [Using Libraries]
Line 29: Line 29:
   java Application   java Application
  
-==== SQLite Library ​====+==== Using Libraries ​====
  
-You can download and use libraries as .jar files. ​You'​ll ​find the SQLite library on Bitbucket at the URL below.+You can download and use libraries as .jar files. ​In this example I'​ll ​load the SQLite-jdbc library. You'll find it on Bitbucket at the URL below.
  
 https://​bitbucket.org/​xerial/​sqlite-jdbc/​downloads https://​bitbucket.org/​xerial/​sqlite-jdbc/​downloads
Line 37: Line 37:
 Download the latest version and place it in the same directory as your application. Download the latest version and place it in the same directory as your application.
  
-Import the file into your application with the following line. In the Hello World example above this will be the first line in the Application.java file.+Import the file into your application with the following line. This line will differ depending on the library you're loading. See the libraries documentation for the exact line to use. For the SQLite-jdbc library, in the Hello World example abovethis will be the first line in the Application.java file.
  
     import java.sql.*;     import java.sql.*;
Line 56: Line 56:
  
 I believe the colon (:) and semi-colon (;) are separators while the dot (.) indicates the current directory. I believe the colon (:) and semi-colon (;) are separators while the dot (.) indicates the current directory.
 +
 +Here's a full example of our Application.java file loading in the library and using it.
 +
 +<​code>​
 +import java.sql.*;
 +
 +public class Application {
 +
 + public static void main(String[] args) {
 +
 +     Connection c = null;
 +     try {
 +       Class.forName("​org.sqlite.JDBC"​);​
 +       c = DriverManager.getConnection("​jdbc:​sqlite:​hello.db"​);​
 +     } catch ( Exception e ) {
 +       System.err.println( e.getClass().getName() + ": " + e.getMessage() );
 +       System.exit(0);​
 +     }
 +     System.out.println("​Opened database (hello.db) successfully"​);​
 +
 + }
 +
 +}
 +</​code>​
comments powered by Disqus
java_introduction.txt · Last modified: 2020/06/01 22:53 (external edit)