aspose file tools*
The moose likes JDBC and the fly likes JDBC Driver connection 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 "JDBC Driver connection" Watch "JDBC Driver connection" New topic
Author

JDBC Driver connection

Rochelle Armstrong
Greenhorn

Joined: Oct 16, 2007
Posts: 5
Have a project in NetBeans and it runs fine out of there (JDBC). When i use the executable jar in another file location it does not connect the driver. Class Not Found Excpetion= com.mysql.jdbc.Driver. Is this all to do with the Connector/J?? In my envioronment Variable under Rob i have this. Variable=CLASSPATH Value=.;c:\mysql-connector-java-5.1.6-bin.jar Also i want to give this software to my friends and have them connect to my mysql database with it. how do i make it a URL? Basically it works other than connecting to the driver

Thanks rob
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
Not sure what NetBeans does, but for running and distribution you need to get it running without NB anyway. If you add a Class-Path (I think) entry to the jar file's manifest, then you can distribute the two jar files together and it'll work as long as they are in the same directory. See http://faq.javaranch.com/java/JarFiles for more information.


Ping & DNS - my free Android networking tools app
Rochelle Armstrong
Greenhorn

Joined: Oct 16, 2007
Posts: 5
Oh so ConnectorJ (jar file) and the classes of my software should be compiled together

roba
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
No, the driver is compiled already, but you need to make sure it's on the classpath both during compilation and at runtime.
Rochelle Armstrong
Greenhorn

Joined: Oct 16, 2007
Posts: 5
So in the .jar file (like a zipped file) you simply add the connector? And what needs to be added to the manifest file just the filename?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
Yes, in the manifest of the jar file in which you distribute your application you'd have a Class-Path (I think) entry with the name of the driver jar file. That works as long as both jar files are in the same directory.
Rochelle Armstrong
Greenhorn

Joined: Oct 16, 2007
Posts: 5
got it to work by changing the manifest file. It now needs a 'lib' folder and the jdbc driver in that 'lib' folder
is this the best way to do it or can both jar files be made into 1 jar file?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
You can un-jar the driver jar file, copy its class files into the class file directory of your application, and then create a new jar file that contains all those class files. In that case you wouldn't have to use a Class-Path entry in the manifest.
Rochelle Armstrong
Greenhorn

Joined: Oct 16, 2007
Posts: 5
Thanks for all your help! Now finally i just have to figure out how to make my database a URL and hopefully connect to it from the net and i am set!

roba
 
 
subject: JDBC Driver connection