Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-24-2008, 02:21 PM
Member
 
Join Date: May 2008
Posts: 5
CompleteBeginner is on a distinguished road
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
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 03:09 PM. Reason: New Problem?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-24-2008, 03:53 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
have you seen the jdbcDriver.class in the path org/hsqldb/*; ?
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-24-2008, 04:30 PM
Member
 
Join Date: May 2008
Posts: 5
CompleteBeginner is on a distinguished road
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 05:40 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP - using connection cache Java Tip Java Tips 0 01-30-2008 11:54 AM
no connection even Database 15 01-02-2008 03:50 PM
Database Connection vipinkumarsolanki Advanced Java 2 11-26-2007 08:36 AM
Database connection oaklander New To Java 2 11-13-2007 01:11 AM
connection pool for db2 paty Database 1 08-06-2007 04:43 AM


All times are GMT +3. The time now is 05:43 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org