| View previous topic :: View next topic |
| Author |
Message |
CajunProgrammer
Joined: 12 Mar 2011 Posts: 10
|
Posted: Sat Mar 12, 2011 4:47 pm Post subject: Using Derby DB in a java application |
|
|
I'm new to the forum. Please excuse any protocols I'm may not have followed in this post.
I have Netbeans 6.9.1 installed. I wrote an application that uses a derby database.
I can connect to the database and create tables and fields in the tables.
I can query the DB also.
However, when I try to access the DB from an application that I wrote, I get a "Driver not found" error when I use Class.forName("org.apache.derby.jdbc.ClientDriver"). |
|
| Back to top |
|
 |
shortrun
Joined: 24 Oct 2009 Posts: 2
|
Posted: Sat Mar 12, 2011 8:46 pm Post subject: |
|
|
Did you set the class path in the operating system?
Here is an example I found by searching-
Windows class path:
C:\Derby\lib\derby.jar;C:\Derby\lib\derbytools.jar;C:\myPath\myDevDir
UNIX class path:
/Derby/lib/derby.jar:/Derby/lib/derbytools.jar:/myPath/myDevDir
I had a similar problems but not with Derby.
It was suggested I needed to set the Class path, which it did try.
I never did figure my problems out. So this is as far as I can go with helping you. |
|
| Back to top |
|
 |
CajunProgrammer
Joined: 12 Mar 2011 Posts: 10
|
Posted: Sat Mar 12, 2011 9:10 pm Post subject: |
|
|
Thank you for replying with your assistance.
Yes, I did try set the classpath. I also tried to set it from your suggestions just in case I did something wrong.
It still doesn't work.
I would have assumed everything would have been installed as it is bundled with netbeans.
I believe it is since I can execute commands on the database from the services tab.
I can only assume that the program cannot see the driver.
If it helps, here is a code snippet.
When the contructor is called, it errors to the ClassNotFoundException.
Again, thanks for assisting.
Code begins here:
package databasetester;
import java.awt.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
/**
*
* @author
*/
public class databaseMgr {
static final String JDBC_DRIVER = "org.apache.derby.jdbc.ClientDriver";
static final String DATABASE_URL = "jdbc:derby://localhost:1527/studentDB";
private Connection connection;
private Statement statement;
public databaseMgr () {
try {
Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL);
statement = connection.createStatement();
}
catch (SQLException sqlException) {
JOptionPane.showMessageDialog (null, sqlException.getMessage(),
"Database Errors", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
catch (ClassNotFoundException classNotFound) {
JOptionPane.showMessageDialog( null, classNotFound.getMessage(),
"Driver Not Found", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
finally {
try{
statement.close();
connection.close();
} // end try
catch (SQLException sqlException) {
JOptionPane.showMessageDialog(null, sqlException.getMessage(), "Database Error",
JOptionPane.ERROR_MESSAGE);
System.exit(1);
} // end catch
} // end finally
} // end databaseMgr |
|
| Back to top |
|
 |
CajunProgrammer
Joined: 12 Mar 2011 Posts: 10
|
Posted: Sun Mar 13, 2011 2:09 am Post subject: ClassPath |
|
|
My installation of glassfish is located at C:\Program Files\glassfish-3.0.1\javadb\lib.
Therefore, I set my classpath as
C:\Program Files\glassfish-3.0.1\javadb\lib\derby.jar;C:\Program Files\glassfish-3.0.1\javadb\lib\derbyclient.jar.
This should account for both the server and the embedded drivers.
Are there any other drivers I need to set in my classpath?
Are there any other netbeans configurations I've missed?
All indications seem to point to a correct configuration. However, I continue to get that same error.
So frustrating. |
|
| Back to top |
|
 |
CajunProgrammer
Joined: 12 Mar 2011 Posts: 10
|
Posted: Sun Mar 13, 2011 2:10 am Post subject: ClassPath |
|
|
My installation of glassfish is located at C:\Program Files\glassfish-3.0.1\javadb\lib.
Therefore, I set my classpath as
C:\Program Files\glassfish-3.0.1\javadb\lib\derby.jar;C:\Program Files\glassfish-3.0.1\javadb\lib\derbyclient.jar.
This should account for both the server and the embedded drivers.
Are there any other drivers I need to set in my classpath?
Are there any other netbeans configurations I've missed?
All indications seem to point to a correct configuration. However, I continue to get that same error.
So frustrating. |
|
| Back to top |
|
 |
markwade
Joined: 04 Dec 2010 Posts: 140
|
Posted: Sun Mar 13, 2011 2:36 am Post subject: Using Derby DB in a java application |
|
|
On Mar 12, 2011, at 4:10 PM, CajunProgrammer wrote:
| Quote: | When the contructor is called, it errors to the
ClassNotFoundException.
|
Did you add the library "JavaDB" to to your project?
In the project properties select the Libraries node in the Categories
tree and click the Add Library button.
Add the JavaDB library.
Mark Wade
address-removed |
|
| Back to top |
|
 |
CajunProgrammer
Joined: 12 Mar 2011 Posts: 10
|
Posted: Sun Mar 13, 2011 3:11 am Post subject: Problem Resolved |
|
|
Mark,
There were no Java DB libraries. However, there were glassfish libraries.
Well, that worked.
So, I thank you very much for your help.
It was very frustrating. But you resolved the issue for me.
Thanks again. I hope I can return the favor one day. |
|
| Back to top |
|
 |
markwade
Joined: 04 Dec 2010 Posts: 140
|
Posted: Sun Mar 13, 2011 1:37 pm Post subject: Re: Problem Resolved |
|
|
| CajunProgrammer wrote: |
There were no Java DB libraries. However, there were glassfish libraries.
Well, that worked.
|
Hmmm, I just checked a different installation on another machine and the JavaDB library isn't there either.
One is 6.8 and the other 6.9.1. That might account for the difference.
Nice job getting it going by substituting the glassfish library. |
|
| Back to top |
|
 |
markwade
Joined: 04 Dec 2010 Posts: 140
|
Posted: Sun Mar 13, 2011 3:10 pm Post subject: Re: Problem Resolved |
|
|
| CajunProgrammer wrote: |
There were no Java DB libraries. However, there were glassfish libraries.
|
You can slim down the dist/lib folder contents if all you need are Derby jars.
Create a JavaDB library. Tools | Libraries | New Library... | Name, accept | Add Jar/Folder...
On my installation I would add this folder:
/usr/local/glassfish-3.0.1/javadb/lib/
No need to distribute a lot of stuff you aren't using. |
|
| Back to top |
|
 |
markwade
Joined: 04 Dec 2010 Posts: 140
|
Posted: Sun Mar 13, 2011 4:06 pm Post subject: Re: Problem Resolved |
|
|
| markwade wrote: |
Create a JavaDB library. Tools | Libraries | New Library... | Name, accept | Add Jar/Folder...
On my installation I would add this folder:
/usr/local/glassfish-3.0.1/javadb/lib/
|
That should work but doesn't. I need to actually specifically add all the jars in that lib folder when I create the library, not just specify the containing lib folder, then it works. |
|
| Back to top |
|
 |
CajunProgrammer
Joined: 12 Mar 2011 Posts: 10
|
Posted: Tue Mar 15, 2011 12:30 am Post subject: |
|
|
I wasn't clear on my response.
All I added were the derby.jar and the derbyclient.jar. I think these would represent the embedded driver and the client server driver.
Yes, I'm all for keeping the application footprint small.
I was confused because I figured since netbeans has an embedded derby implementation (Glassfish), I didn't think I acutally needed to add any further libraries. However, I can see now that I am just adding the drivers to the application. I'm what you call an experienced novice with netbeans. |
|
| Back to top |
|
 |
markwade
Joined: 04 Dec 2010 Posts: 140
|
Posted: Tue Mar 15, 2011 4:29 am Post subject: Using Derby DB in a java application |
|
|
On Mar 14, 2011, at 8:30 PM, CajunProgrammer wrote:
| Quote: | I wasn't clear on my response.
All I added were the derby.jar and the derbyclient.jar. I think
these would represent the embedded driver and the client server
driver.
Yes, I'm all for keeping the application footprint small.
I was confused because I figured since netbeans has an embedded
derby implementation (Glassfish), I didn't think I acutally needed
to add any further libraries. However, I can see now that I am just
adding the drivers to the application. I'm what you call an
experienced novice with netbeans.
|
I've been fighting with a new linux installation. I've installed
NetBeans 6.8 and 6.9.1. 6.8 has a "Java DB Driver" library, 6.9.1 has
no equivalent.
Just for reference, the Java DB Driver library contains derby.jar,
derbyclient.jar, and derbynet.jar.
Adding libraries to a project is just a mechanism for building a
classpath in NetBeans.
I think the classpath in use used to be displayed in the output window
when run or built,
maybe that was JBuilder, it's all getting fuzzy.
Mark Wade
address-removed |
|
| Back to top |
|
 |
|