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
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
Download JDBC zip archive from
https://dev.mysql.com/downloads/connector/j/5.0.html
Extract the file and copy the executable jar file to program files->Java->jdk->bin
Right click on the project and select Buildpath->Add external archives->(Jar file)
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.
Related
I'll keep it short.
I have a project in eclipse using Marvin, the Marvin's jar is added correctly in the build path, classpath.
The problem is, whenever me or someone else exports the project from github and open it in eclipse they have to edit Marvin's Jar path in classpath or to re add it.
I tried to search everywhere for a solution.
Is there one? I don't know. Something like:
new File("src/file.txt")
And then using file.getAbsolutePath() and getting the entire path including the directory (D:\project\src\file.txt)
You can switch to an external build tool, like Maven or Gradle, that will download it for you on whatever machine you're on, or make your Java Build Path reference portable by using a classpath variable that you then manually assign on each Eclipse workspace.
I'm trying to make a program in intelJ that connects to a SQL database, but I receive this error when it tries to find the drivers.
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
I've checked that the directory I use is correct when using Class.forname
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
and it points to the correct location within the Jar file for the driver. I'd assume that that java is unable to find the class for whatever reason, as I've done the exact same thing with a second project which works fine. Any ideas?
You need to add the driver JAR to the classpath of the project.
If you're using a simple Java project: right click on the project in IntelliJ IDEA > Open Module Settings. Then, Project Settings > Libraries. Click on +. Select Java. Browse to the driver JAR. Click OK and it should work.
You need to add it to the module's dependencies. The Libraries section just lists the libraries of this project.
I am using external jar in my mule flow. Jar file make database connection in postgres database. Standalone jar file working fine. But when I use this jar file in my mule it give error
Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver found for jdbc:postgresql://xxx/xxx
I have add postgres jar file in both application as external jar(mule application & standalone jar)
java.sql.SQLException: No suitable driver found for jdbc:postgresql exception come when Java don't find driver from jar file provided.
you have make sure that jar is correct and it present in your project class path.
The exception Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver found for jdbc:postgresql://xxx/xxx clearly says that the jar files is not detected in the classpath .. Now if you are using Mule Standalone you could add the jar in the location ${standaone_installation_folder}/lib/user
and if you are using Mule/anypoint studio you can add by right clicking the project and select java build path and then select add external jar where you select postgresql-jdbc3.jar
or alternately you can also create a lib folder in your project and put the jar file there and then right click on the jar file and add it into classpath
When using Anypoint studio, I would rather play by it's rules to make sure you overcome any classloader hierarchy problems. Postgresql is not supported with a simplified configuration, but in the documentation you'll find that the example actually explains how to use postgresql.
To install the database driver for a generic installation in Studio Visual Editor, follow the steps below:
If you haven't already done so, download the driver for your particular database. For example, the driver for a MySQL database is available for download online.
Add the driver's .jar file to the root folder in your project. In Studio, you can drag and drop the file from your local drive into the project folder.
Add the .jar file to the build path of your project. Right click the project name, then select Build Path > Configure Build Path…
In the wizard that appears, click the Libraries tab, then click Add Jars…
Navigate to the root folder in your project, then select the .jar file for your database driver.
Click OK to save, then OK to exit the wizard. Notice that your project now has a new folder named Referenced Libraries in which your database driver .jar resides.
I am using oci driver to connect to oracle 11.2.0 on Linux, I found that under LD_LIBRARY_PATH, there is only libocijdbc11.so but any ojdbc jar files, is that right? For database connection, am I supposed to add this *.so file to java CP?
I can't test it right away because it is on customer production environment, so just want to get what's the gist first, thanks for any guide!
you can find the ojdbc*.jar files under $ORACLE_HOME/jdbc/lib
and the *.so files must not be included in your CP, but the environment variable LD_LIBRARY_PATH have to be set to the right directory
In Eclipse under project folder->WEB-INF->lib then Right click lib folder->
Build Path->Configure Build Path->Under Libraries->Click on Add External Jars->Computer->Local Disk (C:)->oraclexe->app->oracle->product->10.2.0->server->jdbc->lib->now select ojdbc14.jar
Directly the path is
C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib
C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar
You will get those jars when installing the Oracle Client, the ojdbcX.jar files appear in ORACLE_HOME/jdbc/lib.
The *.so isn't a java library, and it shouldn't be included in the classpath. It should be available in LD_LIBRARY_PATH.
Check out the Verification of a JDBC Client Installation section in the Oracle guide.
We have a simple [spring-hibernate] application (console app) where in we have set the classpath in manifest file of the executable JAR file. And the app connects to the database using jTDS JDBC Driver, Everything works as expected on Windows machine and JDK 1.6, but on Linux, the app is unable to find the driver,
We are running the program using java -jar MainClassName.
Any suggestions why this might be happening is greatly appreciated.
This issue occurred because our jdbc.url had invalid url. This was because maven treats jdbc.url property as a special property and while profiling, instead of url defined in the filter.properties. And that is the reason "No Suitable Driver" exception. The question should have been more clear.
Anyways to fix that we had to rename jdbc.url properties to jdbc.url.somename. This fixed our issue with maven profiling. We also had a similar maven profiling issue for a property called "server.name" This filter property was also confusing maven profiling . We had to change the name of that property as well.
Thanks again Fernando.
Honestly it sounds like bad CLASSPATH. One thing I suggest to start debugging this problem is copying the jtds package to same path as your main packages/classes and see if it works. This way you can assure the Classpath manifest is or isn't the problem. The Spring/Hibernate relies on the lib directory, so it will always be on classpath because it's main structure. Use the lib directory also to test.
Hope this guidelines will help. Also send more information, like paths, classpath and manifest files.
It is a Maven bug
http://jira.codehaus.org/browse/MNG-3563