Adding jdbc driver to classpath

Ok, I am in Win Vista and I am setting my stuff MAVEN_HOME, JAVA_HOME correctly. but I donโ€™t have a way to class yet. I also installed MySQL. I have now opened the Hibernate book, and on the very first pages it says: "Make sure the jdbc driver is in your class path." I also downloaded some Zip file, which is ConnectorJ, or some name similar to what is basically mySql driver for java ... but now my problem is this suggestion that I donโ€™t know how to do it: " make sure the jdbc driver is in your class path "could you help me with this question?

thanks

+6
source share
4 answers

Here is a good tutorial on setting the class path . Next, you can read Java Class Pool Management (Windows) .

Having said that, you should not set the class path for your driver in a Windows environment variable. Instead, you should enable this jar driver inside your IDE in the project properties. But I noticed that you are actually using Maven. In this case, you should look for a driver under Maven to fulfill this dependency. Maven will load the driver pitcher if it does not 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 the necessary jar are there at compile time / run time. You can find HOW in the previous link above.

+7
source

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

What you do when you deploy the application depends on the technologies used.

  • If this command-line application creates the %CLASSPATH% variable or adds the jdbc.jar file path using the java -cp {path\to\jdbc.jar} parameter java -cp {path\to\jdbc.jar} .

  • If this is a web application, you will need to pack the driver box in your .war / .ear / .sar (the maven build plugin can do this) or enable it in. / lib folder the application container and declare it as scope = provided in maven.

+2
source

you can connect directly to the database by following these steps: 1) download mysql-connector-java 5.0.8 and extract the files. 2) then put the folder in the program files. 3), just add this library to your project by right-clicking on it. 4) and here you go. Run the application with db connection.

+1
source

Steps for setting up JDBC projects for Eclipse

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

Source: https://habr.com/ru/post/891069/


All Articles