aspose file tools*
The moose likes JDBC and the fly likes error: Cannot load JDBC driver class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "error: Cannot load JDBC driver class" Watch "error: Cannot load JDBC driver class" New topic
Author

error: Cannot load JDBC driver class

Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69
Hello All,

I'm new to J2EE and I'm figuring out how to make JDBC work. I try to use Initial Context and do lookup for the database but I get this error:

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'org.apache.derby.jdbc.ClientDriver'

I've defined the resource in web.xml:

<resource-ref>
<res-ref-name>jdbc/Friend_DB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

and defined it in context.xml:


<?xml version="1.0" encoding="UTF-8"?>
<Context path="/Friend_Management_System">
<Resource name = "jdbc/Friend_DB" type = "javax.sql.DataSource"
driverClassName = "org.apache.derby.jdbc.ClientDriver"
url = "jdbc:derby://localhost:1527/Friend_DB"
username = "use_name"
password = "pass"
/>
</Context>


Could somebody please advice if there's something else I need to do to make this work?

Thank you very much
[ November 08, 2006: Message edited by: Bear Bibeault ]
Masoud Kalali
Author
Ranch Hand

Joined: Jul 08, 2004
Posts: 531

Hi dude
It means that derby driver is not in your application server classpath.
so you should add derbyClient.jar in your application server common or shared library.
for example it could be glassfish_home\domain1\lib or tomcat_home\shared\lib
what ever place your shared library is.

hth


Masoud Kalali
Software Engineer - My Weblog - GlassFish Security
Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69
Hi,

I put the derbyClient.jar file into the folder: C:\Program Files\netbeans-5.0\enterprise2\jakarta-tomcat-5.5.9\common\lib

The original error disappeared and was replaced by:

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (java.security.PrivilegedActionException : Error

Further, it was said to be "Caused by: org.apache.derby.client.am.DisconnectException: java.security.PrivilegedActionException : Error opening socket to server localhost on port 1527 with message : null"

Could you please help with this? I have no idea what the problem is.

Here is the code that opens the connection:

try
{
Context ctx = new InitialContext();
DataSource datasource = (DataSource) ctx.lookup("java:comp/env/jdbc/Friend_DB");

Connection con = datasource.getConnection();

Statement state = con.createStatement();

ResultSet res = state.executeQuery(select);

person_name = res.getString("person_name");

if(datasource == null)
person_name = "no Datasource";

request.setAttribute("person_name",person_name);

}
catch(Exception e)
{
e.printStackTrace();
}
Masoud Kalali
Author
Ranch Hand

Joined: Jul 08, 2004
Posts: 531

Do you have firewall installed on your machine ?
it looks like that some other application does not allows derby to listen on the port.
Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69
How do I check for this firewall? Could you please advice? Thank you very much
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error: Cannot load JDBC driver class