Results 1 to 4 of 4
  1. #1
    mark8569 is offline Member
    Join Date
    Mar 2008
    Posts
    2
    Rep Power
    0

    Default Trying to get JAVA to work with SQLite

    Hello,
    I am trying to get java to work with SQlite using the following code:

    import java.sql.*;

    public class Main {

    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();
    ResultSet rs = stat.executeQuery("SELECT Question, Answer, Type FROM Questions");
    while (rs.next()) {
    System.out.println(rs.getString("1"));
    System.out.println(rs.getString("2"));
    System.out.println(rs.getString("3"));
    }
    rs.close();
    conn.close();
    }
    }

    But when I try to compile I keep getting the exception:

    Exception in thread "main" java.lang.ClassNotFoundException: org.sqlite.JDBC

    I have looked around other forums and I think I have downloaded the correct drivers for the SQLiteJDBC:
    sqlitejdbc-v043-native.jar and sqlitejdbc.dll from SQLite JDBC Driver.

    I have read that these files need to be put on the classpath and the java library paths respectively however I am unsure how to do this. Also if I do manage to get these files onto their paths would the same have to be done on every computer that I want to run this program on?

    Many thanks

    Mark

  2. #2
    lyuboe is offline Member
    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0

    Default

    i have the same problem, i think it is because i have not said the location of the database..

  3. #3
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    Are you using an IDE to write this or what? If you're using Eclipse I can tell you how to add the JAR files to the classpath
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  4. #4
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    For deployment you should be able to put them in your jar and load the dll with System.loadLibrary()
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

Similar Threads

  1. Ho to work with enumerations in java
    By zizou147 in forum Advanced Java
    Replies: 0
    Last Post: 03-22-2008, 12:53 PM
  2. JAVA and SQLite
    By mark8569 in forum Advanced Java
    Replies: 0
    Last Post: 03-20-2008, 06:17 PM
  3. Pass by ref. A work around?
    By diRisig in forum New To Java
    Replies: 0
    Last Post: 02-05-2008, 07:25 PM
  4. how would i get this to work...?
    By deeadeed in forum New To Java
    Replies: 6
    Last Post: 12-06-2007, 02:58 AM
  5. will java webBrowser work with frames
    By elipford in forum New To Java
    Replies: 2
    Last Post: 06-04-2007, 03:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •