开发者

Adding jdbc driver to classpath

Ok I am on Win Vista and correctly set my MAVEN_HOME, JAVA_HOME stuff. but I do not have a class path 开发者_JAVA技巧yet. I have also installed MySQL. now I have opened a Hibernate book and at the very first pages it says "make sure the jdbc driver is in your classpath" . I have also downloaded some Zip file that is ConnectorJ or some name like that which is basically the mySql driver for java... but my problem for now is this sentence that I have no clue how to do it: "make sure the jdbc driver is in your classpath" would you please help me about this classpath thing?

thanks


Here is a good tutorial regarding, setting the class path. Further you might like to read Managing the Java classpath (Windows).

Having said that, you should not set the classpath for your driver in Windows environment variable. Instead, you should include that driver jar inside your IDE under project properties. But I noticed that you are actually using Maven. In this case you should look for the driver under Maven in order to fulfil that dependency. Maven will download the driver jar, if doesn't exist, and make it local.

In case, you are not using any IDE, then you can create a lib directory and tell the compiler that all required jars are in there, at the time of compilation/execution. You can find HOW, in the former link given above.


Since you are using Maven, you just need to put the JDBC driver as a dependency in your pom.xml file. Maven will add it to the classpath whenever it compiles/runs your application.

What you do when deploying your application is dependent on the technologies in use.

  • If it's a command line application create a %CLASSPATH% variable or add the path to the jdbc.jar file using the java -cp {path\to\jdbc.jar} option.

  • If it's a web application, you'll need to package the driver jar in your .war/.ear/.sar (the maven assembly plugin can do this) or include it in the ./lib folder of the application container and declare it as scope=provided in maven.


Steps to setup JDBC for Eclipse projects

  1. Download JDBC zip archive from https://dev.mysql.com/downloads/connector/j/5.0.html
  2. Extract the file and copy the executable jar file to program files->Java->jdk->bin
  3. Right click on the project and select Buildpath->Add external archives->(Jar file)
  4. Compile the program


you can directly connect database by following steps: 1) download mysql-connector-java 5.0.8 and extract the files. 2) then place the folder in program files. 3) then simply add this library on your project by right clicking on it. 4) and here you go. Run your app with db connectivity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜