Java JDBC using SQLite/Preparation

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Assuming that you have a Java environment correctly configured, and that you can run up a simple HelloWorld program, etc, the first thing is to locate your JDBC jar file and add it to your classpath.

Classpathing Windows[edit | edit source]

In Windows environments this is typically done by entering your Control Panel, available from the Start menu, clicking the System icon, and then selecting the Advanced System settings option, selecting the Advanced tab, followed by hitting the Environment Variables button. This is marginally different in the various Windows OS environments but at the end of the day you need to be able to set your environment variables. If you share the computer, probably the best thing to do is to create a CLASSPATH variable in your local user settings, unless, of course you want other users to also be able to access the jar file.

If one already exists you can just append the fully qualified path and file name to the existing entries in the CLASSPATH variable, using a semi-colon as a separator e.g. where you had a CLASSPATH string which looked like:


and you had renamed and put the SqlLite jar file in the same directory as the existing entry, as c:\jars\SqliteJdbc.jar, your amended CLASSPATH string will now look like:


You can check the status of your CLASSPATH environment variable by typing SET CLASSPATH at the command prompt.

NB if you are already working in a DOS command box, changes will not become apparent in that session, you will need to start a new command box for the changes to be realised.

Classpathing Unix shells[edit | edit source]

The syntax for your classpathing will depend on the shell you are using, and can be fully discovered by using the "man {shellname}" command.

bash & ksh syntax:

export CLASSPATH=$CLASSPATH:/java/classes:/home/jars/SqliteJdbc.jar

csh syntax:

set CLASSPATH = ($CLASSPATH /java/classes /home/jars/SqliteJdbc.jar)

To view your CLASSPATH environment variables, "echo $CLASSPATH" will show you what you need to know.