設定
[1] 以下のサイトから、JDBCドライバーをダウンロードする (例えば、「sqlite-jdbc-3.7.2.jar」)https://bitbucket.org/xerial/sqlite-jdbc
[2] Eclipse で、新規プロジェクトを作成 [3] 新規プロジェクトのあるフォルダに、任意のフォルダ(例えば「lib」)を作成し その配下に、JDBCドライバーのJarファイルを置く (【新規プロジェクトのあるフォルダ】\lib\sqlite-jdbc-3.7.2.jar) [4] そのプロジェクトを右クリックし、[Properties]-[Java Build Path]-[Libraries]-[Add JARs]を選択し 手順[3]のJARファイルを追加する
サンプル
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class SampleSqlLite { public static void main(String[] args) throws ClassNotFoundException { Class.forName("org.sqlite.JDBC"); Connection connection = null; try { connection = DriverManager.getConnection("jdbc:sqlite:C:\\pg\\sqlite\\sample.sqlite3"); Statement statement = connection.createStatement(); statement.setQueryTimeout(30); // set timeout to 30 sec. ResultSet results = statement.executeQuery("select * from Person"); while (results.next()) { System.out.println("name = " + results.getString("name")); System.out.println("id = " + results.getInt("id")); } } catch (SQLException e) { System.err.println(e.getMessage()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { System.err.println(e); } } } }
参考文献
http://ichitcltk.hustle.ne.jp/gudon/modules/pico_rd/index.php?content_id=72http://leoclock.blogspot.jp/2008/10/sqlitejdbc-javasqlite.html
http://www.hlplus.jp/blog/java/194/