Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC Driver connection

 
Rochelle Armstrong
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rochelle Armstrong
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh so ConnectorJ (jar file) and the classes of my software should be compiled together

roba
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic