12

Ok I am on Win Vista and correctly set my MAVEN_HOME, JAVA_HOME stuff. but I do not have a class path 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

Adeel Ansari
  • 39,541
  • 12
  • 93
  • 133
Bohn
  • 26,091
  • 61
  • 167
  • 254
  • 1
    What IDE are you using? Eclipse? I think you'll have to edit your pom file to declare that you actually need the jdbc classes, and Maven will take care of the rest. –  Jun 22 '11 at 02:36
  • eventually I will be using EClipse ..but this is a learning book -Hibernate Made Easy- and intentionally it is not even using Maven to simplify things and examples as much as possible..it is teaching Hibernate with minimum things needed to have...so at this point I do not use a POM yet. – Bohn Jun 22 '11 at 02:41
  • Are you using any build tool? If so, please provide the information. – bhagyas Jun 22 '11 at 06:27
  • @bhagyas: we will be using Maven,Eclipse,Spring for the real project at work but since I dunno hibernate yet and I want to learn it from a book I thought the simplest thing is to stay away from all other learning curves than setting Maven,...will bring to me.. so I like to set it up to a minimum that I can run some very simple examples of the book and continue reading it.. – Bohn Jun 22 '11 at 14:09
  • 1
    @BDotA Setting up Maven is quite easy and probably the easiest way if you are experimenting with different libraries. If you are using eclipse, just select new Maven Project from Eclipse new Project Dialog, and you're good to go. Just add hibernate as a dependency to your project and Maven will take care of the rest. Wish you all the best :) – bhagyas Jun 22 '11 at 14:37

4 Answers4

7

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.

Adeel Ansari
  • 39,541
  • 12
  • 93
  • 133
2

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
bish
  • 3,381
  • 9
  • 48
  • 69
2

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.

Chris Nava
  • 6,614
  • 3
  • 25
  • 31
1

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.

Mohit daga
  • 11
  • 1