Results 1 to 3 of 3
  1. #1
    Join Date
    May 2008
    Posts
    5
    Rep Power
    0

    Default Database Connection

    Hi im trying to create a database and table from a .class and also want to use Open Office base which i think employs HSQL.

    I think its a problem with the drivers.

    heres my code
    Java Code:
    import java.io.*;
    import java.sql.*;
    
    public class Presidents {
    String home, system;
    
    public Presidents() {
    home = System.getProperty("user.home", ".");
    system = home + File.separatorChar + ".odb";
    System.setProperty("hsqldb.system.home", system);
    }
    
    public void createDatabase() {
    // set the database directory
    String datasource = "jdbc:hsqldb:presidents;create=true";
    try {
    //load the driver
    Class.forName("org.hsqldb.jdbcDriver");
    Connection conn = DriverManager.getConnection(datasource);
    Statement st = conn.createStatement();
    //create the contacts table
    int result = st.executeUpdate(
    "CREATE TABLE contacts ("
    + "dex INTEGER NOT NULL PRIMARY KEY "
    + "GENERATED ALWAYS AS identity "
    + "(START WITH 1, INCREMENT BY 1), "
    + "name VARCHAR(40), "
    + "address1 VARCHAR(40), "
    + "address2 VARCHAR(40), "
    + "phone VARCHAR(20), "
    + "email VARCHAR(40))");
    //insert a record
    result= st.executeUpdate(
    "INSERT INTO contacts (name, address1, address2, " + "phone, email) VALUES("
    + "'Jimmy Carter', "
    + "'Prsidential Center', "
    + "'680592', "
    + "'carter@carter.edu')");
    st.close();
    System.out.println("Database created");
    } catch (Exception e) {
    System.out.println("Error - " + e.toString());
    }
    }
    
    public void readDatabase() {
    String datasource = "jdbc:hsqldb:presidents";
    try {
    //load driver and connect to database
    Class.forName("org.hsqldb.jdbcDriver");
    Connection conn = DriverManager.getConnection(datasource, "","");
    Statement st = conn.createStatement();
    ResultSet rec =st.executeQuery(
    "SELECT * FROM contacts");
    while(rec.next()) {
    System.out.println(rec.getString("name") + "\n" + rec.getString("address1") + "\n"
     + rec.getString("address2") + "\n" + rec.getString("phone") + "\n" + rec.getString("email") + "\n");
    }
    st.close();
    } catch (Exception e) {
    System.out.println("error - " + e.toString());
    }
    }
    
    public static void main(String[] arguments) {
    Presidents prez = new Presidents();
    if (arguments[0].equals("create")) {
    prez.createDatabase();
    }
    if (arguments[0].equals("read")) {
    prez.readDatabase();
    }
    }
    }
    Error Message i get is:
    java.lang.ClassNotFoundException: org.hsqldb.jdbcDriver

    Any help appreciated.
    Last edited by CompleteBeginner; 05-24-2008 at 02:09 PM. Reason: New Problem?

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    have you seen the jdbcDriver.class in the path org/hsqldb/*; ?
    freedom exists in the world of ideas

  3. #3
    Join Date
    May 2008
    Posts
    5
    Rep Power
    0

    Default

    Firstly thank you for your reply.

    The jdbcDriver.class was in the hsqldb.jar file i extracted the jar file and palced the contents into src.zip under correct path structure still nothing.
    Last edited by CompleteBeginner; 05-24-2008 at 04:40 PM.

Similar Threads

  1. JSP - using connection cache
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-30-2008, 10:54 AM
  2. no connection
    By even in forum JDBC
    Replies: 15
    Last Post: 01-02-2008, 02:50 PM
  3. Database Connection
    By vipinkumarsolanki in forum Advanced Java
    Replies: 2
    Last Post: 11-26-2007, 07:36 AM
  4. Database connection
    By oaklander in forum New To Java
    Replies: 2
    Last Post: 11-13-2007, 12:11 AM
  5. connection pool for db2
    By paty in forum JDBC
    Replies: 1
    Last Post: 08-06-2007, 03:43 AM

Posting Permissions

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