Derby Connection Issues

Reply

Join Date: Aug 2008
Posts: 205
Reputation: llemes4011 is an unknown quantity at this point 
Solved Threads: 13
llemes4011 llemes4011 is offline Offline
Posting Whiz in Training

Derby Connection Issues

 
0
  #1
Sep 28th, 2009
Hello, I'm using NetBeans 6.7.1, and Derby 10.5.3.0. I'm trying to learn how to write Database applications, and I'm having trouble connecting to my Database. It loads the Derby Driver (EmbeddedDriver), but won't connect to the the Database named test. I looked at tests Properties in NetBeans, and it said that it was using the org.apache.jdbc.derby.ClientDriver. I did create the Database, and give it no username or password. Below is the code that I have. If anybody could help, that would be great =D

  1. package jdb.test;
  2. import java.sql.*;
  3.  
  4. public class DatabaseTest {
  5.  
  6. public static void main(String[] args){
  7. try{
  8. // Load the EmbeddedDriver class
  9. Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
  10. System.out.println("Loaded Derby Driver");
  11. }catch(Exception e){
  12. e.printStackTrace();
  13. System.out.println("Error loading Derby Driver. Shutting down.");
  14. System.exit(-1);
  15. }
  16.  
  17. // The database located on my computer
  18. String database = "jdbc:derby://localhost:1527/test";
  19. try{
  20. // Connect without a username and password
  21. Connection conn = DriverManager.getConnection(database);
  22. System.out.println("Connected to "+database);
  23. }catch(SQLException e){
  24. e.printStackTrace();
  25. System.out.println("Could not connect to "+database);
  26. System.exit(-1);
  27. }
  28. System.out.println("You have connect to the selected database.");
  29. }
  30. }

This is the error that I get:
  1. java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/test
  2. at java.sql.DriverManager.getConnection(DriverManager.java:602)
  3. at java.sql.DriverManager.getConnection(DriverManager.java:207)
  4. at jdb.test.DatabaseTest.main(DatabaseTest.java:22)
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,454
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Derby Connection Issues

 
0
  #2
Sep 28th, 2009
Your code is loading the EmbeddedDriver class, but using the ClientDriver network url for your connection string. The EmbeddedDriver uses the database name instead of the //servername url.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 205
Reputation: llemes4011 is an unknown quantity at this point 
Solved Threads: 13
llemes4011 llemes4011 is offline Offline
Posting Whiz in Training

Re: Derby Connection Issues

 
0
  #3
Sep 28th, 2009
I tried using "jdbc:derby:test" instead of ""jdbc:derby://localhost:1527/test", but it gave me this error:

(this is the entire output from the execution)
  1. Loaded Derby Driver
  2. java.sql.SQLException: Database 'test' not found.
  3. at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
  4. at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
  5. at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
  6. at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
  7. at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source)
  8. at org.apache.derby.impl.jdbc.EmbedConnection.handleDBNotFound(Unknown Source)
  9. at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown Source)
  10. at org.apache.derby.impl.jdbc.EmbedConnection30.<init>(Unknown Source)
  11. at org.apache.derby.impl.jdbc.EmbedConnection40.<init>(Unknown Source)
  12. at org.apache.derby.jdbc.Driver40.getNewEmbedConnection(Unknown Source)
  13. at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
  14. at org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown Source)
  15. Could not connect to jdbc:derby:test
  16. at java.sql.DriverManager.getConnection(DriverManager.java:582)
  17. at java.sql.DriverManager.getConnection(DriverManager.java:207)
  18. at jdb.test.DatabaseTest.main(DatabaseTest.java:22)
  19. Caused by: java.sql.SQLException: Database 'test' not found.
  20. at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
  21. at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
  22. ... 15 more
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,454
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Derby Connection Issues

 
0
  #4
Sep 28th, 2009
Yes, that is just a path issue.
http://db.apache.org/derby/docs/10.5/devguide/
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 205
Reputation: llemes4011 is an unknown quantity at this point 
Solved Threads: 13
llemes4011 llemes4011 is offline Offline
Posting Whiz in Training

Re: Derby Connection Issues

 
0
  #5
Sep 28th, 2009
I tried setting the derby.system.home property to the location where I was storing the databases, but that didn't help either. It looks like I'm structuring everything correctly... I'm sorry, I think I'm missing something really obvious >.<
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,454
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Derby Connection Issues

 
0
  #6
Sep 28th, 2009
Well, I can only point to the docs:
http://db.apache.org/derby/docs/10.5...dvlp40350.html
and experimentation with the path you're using in the connection string.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 205
Reputation: llemes4011 is an unknown quantity at this point 
Solved Threads: 13
llemes4011 llemes4011 is offline Offline
Posting Whiz in Training

Re: Derby Connection Issues

 
0
  #7
Sep 28th, 2009
Thank you for all of your help If I find anything, I'll post it here.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 205
Reputation: llemes4011 is an unknown quantity at this point 
Solved Threads: 13
llemes4011 llemes4011 is offline Offline
Posting Whiz in Training

Re: Derby Connection Issues

 
0
  #8
Sep 28th, 2009
AHA! I used the create property to create a new Database, and then searched for it using the OS's Search Program. I found the newly created database in the NetBeans project folder. I can not successfully connect to the database. I don't know how to add that new Database to the list of databases that are editable directly through NetBeans.
Reply With Quote Quick reply to this message  
Reply

Tags
derby, java, netbeans, sql

Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC