943,737 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 4550
  • Java RSS
Sep 28th, 2009
0

Derby Connection Issues

Expand Post »
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

Java Syntax (Toggle Plain Text)
  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:
Java Syntax (Toggle Plain Text)
  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)
Similar Threads
Reputation Points: 41
Solved Threads: 13
Posting Whiz in Training
llemes4011 is offline Offline
224 posts
since Aug 2008
Sep 28th, 2009
0

Re: Derby Connection Issues

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.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Sep 28th, 2009
0

Re: Derby Connection Issues

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)
Java Syntax (Toggle Plain Text)
  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
Reputation Points: 41
Solved Threads: 13
Posting Whiz in Training
llemes4011 is offline Offline
224 posts
since Aug 2008
Sep 28th, 2009
0

Re: Derby Connection Issues

Yes, that is just a path issue.
http://db.apache.org/derby/docs/10.5/devguide/
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Sep 28th, 2009
0

Re: Derby Connection Issues

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 >.<
Reputation Points: 41
Solved Threads: 13
Posting Whiz in Training
llemes4011 is offline Offline
224 posts
since Aug 2008
Sep 28th, 2009
0

Re: Derby Connection Issues

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.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Sep 28th, 2009
0

Re: Derby Connection Issues

Thank you for all of your help If I find anything, I'll post it here.
Reputation Points: 41
Solved Threads: 13
Posting Whiz in Training
llemes4011 is offline Offline
224 posts
since Aug 2008
Sep 28th, 2009
0

Re: Derby Connection Issues

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.
Reputation Points: 41
Solved Threads: 13
Posting Whiz in Training
llemes4011 is offline Offline
224 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: MySQL Connector
Next Thread in Java Forum Timeline: Server - Client thing





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC