Cannot get Class.forName("com.mysql.jdbc.Driver"); to work

10 views
Skip to first unread message

tedpottel

unread,
Jan 7, 2010, 2:56:20 PM1/7/10
to Java EE (J2EE) Programming with Passion!
Hi,
I have successfully madea program that access my sql database sevrer.
I tried to create another project connecting to the same data base and
cannot get it to work, I even ended up copying over the code from the
other project. Both projects are in net beans.

I was able to track the problem down to
Class.forName("com.mysql.jdbc.Driver");
Which seems to be setting off an exception.


I have the following code
out.println("pos a");
Class.forName("com.mysql.jdbc.Driver");
out.println("pos b");
The pos gest printed out, and pos b does not. The catch cathes an
exception .

Why does Class.forName("com.mysql.jdbc.Driver"); set of an exception,
it works fine in my other project.?
Ted

Niteen Kumar

unread,
Jan 7, 2010, 3:09:38 PM1/7/10
to tedp...@gmail.com, Java EE (J2EE) Programming with Passion!
Did u add the relevant jar files to classpath?

 
--
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
java-ee-j2ee-progr...@googlegroups.com
To unsubscribe from this group, send email to
java-ee-j2ee-programming...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en



--
Thanks & Regards
Niteen Kumar


Mihai DINCA

unread,
Jan 7, 2010, 3:09:44 PM1/7/10
to tedp...@gmail.com, Java EE (J2EE) Programming with Passion!
Hi Ted,

The library that contains the class "com.msql.jdbc.Driver" must be in
the classpath. To do that, go to the "properties" of your project (right
click) and look in the section libraries. You must have the same
libraries in the two projects in order to get it working.

Hope it helps
mihai


tedpottel a �crit :

akshay chandu

unread,
Jan 7, 2010, 3:15:31 PM1/7/10
to tedp...@gmail.com, Java EE (J2EE) Programming with Passion!
Hi,
    I think the issue is you have not added the jdbc jar file to the second netbeans project.
So the exception is being thrown,as particular class is not found.

Regards,
Akshay.

On Thu, Jan 7, 2010 at 2:56 PM, tedpottel <tedp...@gmail.com> wrote:

Zahari

unread,
Jan 8, 2010, 11:20:10 AM1/8/10
to Java EE (J2EE) Programming with Passion!
What's the type of the exception ?
Reply all
Reply to author
Forward
0 new messages