NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
beginner_83
Joined: 01 Mar 2010 Posts: 3
|
Posted: Fri May 07, 2010 7:50 pm Post subject: Help with connecting to a database |
|
|
Hi Everyone
I'm trying to set up a database and connect to it, this is the first time I've tried it and it's not going well. I followed several tutorials but I'm still getting errors. First of all, I followed a tutorial to set up JavaDBEmbedded library. I created a database following another tutorial. I selected the properties of the Project and in the libraries option I added the JavaDBEmbedded library under the 'compile' tab. When I try and run the code..
| Code: | try
{
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/AddressBook","user", "password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM Contacts");
while (rs.next())
{
String s = rs.getString("FirstName");
//float n = rs.getFloat("Age");
System.out.println(s + " " );
}
} |
I'm getting the error..
java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/AddressBook
This is being created at this line..
| Code: | | Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/AddressBook","user", "password"); |
I've noticed on the properties of the database the driver is
org.apache.derby.jdbc.ClientDriver
Could this be the problem??
I'd appreciate some help or advice.
Thanks in advance |
|
| Back to top |
|
 |
netero
Joined: 25 May 2009 Posts: 207 Location: Switzerland
|
Posted: Thu May 13, 2010 9:01 pm Post subject: |
|
|
Hello,
I did not try what I am going to tell you, but it seems to me that there are some parts missing. So please could you try with this:
| Code: | java.sql.Driver driver;
// The newInstance() call is a work-around for some broken Java implementations
driver = (Driver) Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
DriverManager.registerDriver(driver);
|
... and only after that will come your DriverManager.getConnection(...);
Ok with it?
netero |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|