Connecting Sqlite with JDeveloper
ezez85Sep 22 2009 — edited Sep 23 2009Hi guy,
I am new to Jdeveloper and i am trying to connect the application i create to the SQLite. I setup the SQLite through the connection Create Database Wizard. However, when i run,
error occur.
java.lang.ClassNotFoundException: org.sqlite.JDBC
I tried to search but there are little about using oracle and sqlite. Is there any step i miss when i create the connection. Thank a lot!!!
this is my sample code:
import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.ResultSetMetaData;
import java.sql.DatabaseMetaData;
public class HelloDatabase
{
public static void main (String[] args)
{
// register the driver
String sDriverName = "org.sqlite.JDBC";
try
{
Class.forName(sDriverName);
}
catch(Exception e)
{
System.err.println(e);
}
// now we set up a set of fairly basic string variables to use in the body of the code proper
String sTempDb = "sample.db";
String sJdbc = "jdbc:sqlite"; String sDbUrl = sJdbc + ":" + sTempDb;
// which will produce a legitimate Url for SqlLite JDBC :
// jdbc:sqlite:hello.db
int iTimeout = 30;
String sMakeTable = "CREATE TABLE dummy (id numeric, response text)";
String sMakeInsert = "INSERT INTO dummy VALUES(1,'Hello from the database')";
String sMakeSelect = "SELECT response from dummy";
try
{ // create a database connection
Connection conn = DriverManager.getConnection(sDbUrl);
Statement stmt = conn.createStatement();
stmt.setQueryTimeout(iTimeout);
stmt.executeUpdate( sMakeTable );
stmt.executeUpdate( sMakeInsert ); ResultSet rs = stmt.executeQuery(sMakeSelect);
while(rs.next())
{
String sResult = rs.getString("response");
System.out.println(sResult);
}
}
catch(SQLException e)
{
// connection failed.
System.err.println(e);
}
}
}