This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

connection not possible, even after using the connector

 
aditya sural
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried doing a simple connection with the database using java. I am using netbeans in ubuntu 9.10. I included the required connector for mysql database. This is my program-


I am getting following exceptions-
Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at test.main(test.java:13)
Java Result: 1
I am new to JDBC. Please, please help
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
com.mysql.jdbc.Driver is not on your classpath.
 
athi ram
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thing Driver file is missing. So check Driver File in lib folder..



 
Jan Cumps
Bartender
Posts: 2602
13
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And remove the ".newInstance()" part. That does not belong there.
 
aditya sural
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am learning this with two others. They are having no problems. We are working out these problems in our institute labs.
I would like to know where this Driver should be.
 
aditya sural
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And also I removed .newInstance(). But still not working
 
anirudh jagithyala
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you install the SQL jdbc driver...?

The link might help you
http://www.devdaily.com/java/edu/pj/pj010024
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the sake of completeness, and in case you're copying very old code:
1) when a JDBC Driver is loaded, it is required to register itself with the ClassLoader (if you're new you can just assume this is 'static initialiser' magic and look into it another day)
2) When you DriverManager.getConnection(...) the DriverManager asks each of the Drivers that it knows about if they understand that URL. If one says 'yes' then that Driver is asked to return a Connection

Applying this to your code:

This causes the Class to be loaded by the ClassLoader. As in rule 1 above, it then registers itself with the DriverManager

The reason why I asked if you were referring to old code is that this code was required in Java 1.2 to manage a problem with ClassLoaders not immediately loading Classes. Java 1.2 is long gone so this is no longer required.
Worse, as it creates an instance of the Class but that Class is never used, it creates the possibility of a large number of unused instances waiting to be Garbage Collected.
Again this isn't something to worry about at this stage, just don't do it ;)
 
aditya sural
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. I am using netbeans and I added the mysql-connector jar file. But still throwing classNotFound exception
 
aditya sural
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David O'Meara wrote:For the sake of completeness, and in case you're copying very old code:
1) when a JDBC Driver is loaded, it is required to register itself with the ClassLoader (if you're new you can just assume this is 'static initialiser' magic and look into it another day)
2) When you DriverManager.getConnection(...) the DriverManager asks each of the Drivers that it knows about if they understand that URL. If one says 'yes' then that Driver is asked to return a Connection

Applying this to your code:

This causes the Class to be loaded by the ClassLoader. As in rule 1 above, it then registers itself with the DriverManager

The reason why I asked if you were referring to old code is that this code was required in Java 1.2 to manage a problem with ClassLoaders not immediately loading Classes. Java 1.2 is long gone so this is no longer required.
Worse, as it creates an instance of the Class but that Class is never used, it creates the possibility of a large number of unused instances waiting to be Garbage Collected.
Again this isn't something to worry about at this stage, just don't do it ;)



Ok. I just copied that file for startup.It was the simplest ,so.. Thank you very much for the help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic