[SQLiteJDBC] Configuration

Andy Wilbourn awilbourn at gmail.com
Wed Jan 13 22:25:27 EST 2010


Me again, I just found what I needed. This person's instructions got me
going, now to integrate my code to read and write the data.

http://www.code-purity.com/sqlite_for_netbeans/ 


-----Original Message-----
From: Andy Wilbourn [mailto:awilbourn at gmail.com] 
Sent: Wednesday, January 13, 2010 10:07 PM
To: 'Christopher Bare'
Cc: 'sqlitejdbc at lists.hcoop.net'
Subject: RE: [SQLiteJDBC] Configuration

So I have been looking around and found a different way to include the JAR
file. Project Properties->Java Build Path->Libraries tab, I chose Add
Library, then chose connectivity Driver Definition. The SQLite was in the
list, I just needed to point to where my JAR file was. Now one things it
also show is where the native library is, I thought everything is in the JAR
file, am I supposed to have some DLL somewhere and that is the class
definition missing? If so, then how does this make it portable for all
platforms?

Thanks.

-----Original Message-----
From: Christopher Bare [mailto:cbare at systemsbiology.org] 
Sent: Wednesday, January 13, 2010 1:43 PM
To: Andy Wilbourn
Subject: Re: [SQLiteJDBC] Configuration

Hi Andy,

As the AJ suggested, the easiest method is to stick the
Class.forName(...) in a static initializer block on the class that
makes use of JDBC. The try/catch is necessary as forName() throws a
checked exception. That's the only reason you'd get compilation
problems on that line that I can think of.

You'll get a ClassNotFoundException at runtime if the JVM can't find
the SQLite jar. That jar needs to be on the classpath.

In eclipse, you'll need to add the jar to your build path.
(sqlitejdbc-v056.jar, unless there's a more recent version.) It's
somewhat standard to organize a java project something like this:

/MyProject/
  src/main/
    com/mycompany/myprogram/Main.java
    com/mycompany/myprogram/db/SQLiteDataSource.java
    com/mycompany/myprogram/anotherpackage/MyDomainObject.java
  src/test/
    com/mycompany/myprogram/db/TestSQLiteDataSource.java
  lib/
    sqlitejdbc-v056.jar


In eclipse, you can right-click on a folder then select Build Path |
Use as Source Folder. You'll have to do that to src/main and src/test
if you follow this template. Likewise, you need to add the SQLite jar
by right clicking on it and selecting Build Path | Add to Build Path.

The idea is that Main holds your entry point (main method).
SQLiteDataSource makes all your JDBC calls. It's purpose is to wrap
the DB access and expose methods in terms of your domain (say for
example, methods to create, read, update, and delete (CRUD) customer
objects, product objects, order object, etc.). There are many ways to
approach the mapping of Java objects to database entities, but I'm
assuming you want to keep it simple.

Sorry, if this is more advice than you wanted. If you still have
trouble, post code snippets and a stack trace. Good luck.

-chris




More information about the SQLiteJDBC mailing list