Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found your question while searching for information with <a href="http://www.sqlite.org/" rel="noreferrer">SQLite</a> and Java. Just thought I'd add my answer which I also posted on my <a href="http://blog.rungeek.com/post/81611917/how-to-use-sqlite-with-java" rel="noreferrer">blog</a>.</p> <p>I have been coding in Java for a while now. I have also known about SQLite but never used it… Well I have used it through other <a href="http://www.sqlite.org/famous.html" rel="noreferrer">applications</a> but never in an app that I coded. So I needed it for a project this week and it's so simple use!</p> <p>I found a Java JDBC driver for SQLite. Just add the <a href="https://github.com/xerial/sqlite-jdbc" rel="noreferrer">JAR file</a> to your classpath and import java.sql.*</p> <p>His test app will create a database file, send some SQL commands to create a table, store some data in the table, and read it back and display on console. It will create the <strong>test.db</strong> file in the root directory of the project. You can run this example with <code>java -cp .:sqlitejdbc-v056.jar Test</code>.</p> <pre><code>package com.rungeek.sqlite; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; public class Test { public static void main(String[] args) throws Exception { Class.forName("org.sqlite.JDBC"); Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db"); Statement stat = conn.createStatement(); stat.executeUpdate("drop table if exists people;"); stat.executeUpdate("create table people (name, occupation);"); PreparedStatement prep = conn.prepareStatement( "insert into people values (?, ?);"); prep.setString(1, "Gandhi"); prep.setString(2, "politics"); prep.addBatch(); prep.setString(1, "Turing"); prep.setString(2, "computers"); prep.addBatch(); prep.setString(1, "Wittgenstein"); prep.setString(2, "smartypants"); prep.addBatch(); conn.setAutoCommit(false); prep.executeBatch(); conn.setAutoCommit(true); ResultSet rs = stat.executeQuery("select * from people;"); while (rs.next()) { System.out.println("name = " + rs.getString("name")); System.out.println("job = " + rs.getString("occupation")); } rs.close(); conn.close(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload