I'm trying to connect to a remote database using the following java code, but I get an error saying no suitable driver found.
DriverManager.getConnection("odbc:db2://url:port/dbname");
Class.forName("com.ibm.db2.jcc.DB2Driver");
What could I be doing wrong?
Two comments:
1. You have to load the driver first, before trying to use it
2. If I am not mistaken, the driver you are loading is a JDBC driver for DB2 UDB, not ODBC. The connection URL for it is "jdbc:db2//host:port/database"
So your code should look something like this:
Class.forName("com.ibm.db2.jcc.DB2Driver");
DriverManager.getConnection("jdbc:db2://host_or_ip_address:port/dbname");
I found the solution...I didn't add the JAR files for the driver.
You should add jar files of db2cc.jar,db2jcc_license_cu.jar and db2jcc_license_cisuz.jar files into your classpath location and these jar files held in your db2 installation directory location under java folder you got the above jar files
Related
Whenever I run the DS job I am getting following issue
"Error loading connector library cctera12.dll. The specified module could not be found.
(CC_LoadedConnector::loadLibrary, file CC_ConnectorFactory.cpp, line 1,536)"
But cctera12.dll this library is present in dscomponents and also mentioned that path in system path.
Please help to solve this issue , thanks .
here are few steps you can follow.
ensure that LD_LIBRARY_PATH is having link to the DSComponents/bin folder.
With your #tags i assume that you are facing issue with Teradata database so make sure that the LD_LIBRARY_PATH is updated with Teradata home location. If its oracle db ORACLE_HOME location should be present in library.
you may need to restart your datastage server and services
I am trying to use the Squirrel SQL client to connect to a H2 server instance.
The problem I am facing is that when I hit the "connect" button of the server I want to connect to, then I am getting a:
ClassNotFoundException: org.h2.Driver
I thought it was because h2.jar was not in the classpath. Then I edited squirrel-sql.bar to try two things.
The first thing I tried is to add the JAR into the PATH like this:
SET PATH=%PATH%;C:\Program Files\squirrel-sql-3.5.3\plugins\h2.jar
Then I restarted Squirrel. Same error.
Then I tried adding:
set TMP_CP=%TMP_CP%;"C:\Program Files\squirrel-sql-3.5.3\plugins\h2.jar"
Then I restarted Squirrel. Same error.
When I look at the console, I can see that h2.jar is in the PATH and/or the SQUIRREL_CP but the same error occurs all the time.
I am wondering if I am not forgetting something bout how to install/configure SQuirrel and/or H2?
Rather than modifying the batch files every time you use a different driver just modify the drivers classpath through the GUI.
Double click on the appropriate driver in the Drivers tab then click on the "Extra Class Path" tab and add the driver jar.
You can find more information under "How to connect to a Database" in the SQuirreL section in the Help file. Press F1 in SQuirreL to see the Help file. You can see a screenshot at http://www.squirrelsql.org/screenshots/driver.html
I found the issue to my problem. I was linking to the h2 file in Squirrel SQL. However, I had to link to the h2 file from the H2 application... What I did to solve my issue is to add a line to the addpath.bat file such that the file looks like:
set TMP_CP=%TMP_CP%;%1
set TMP_CP=%TMP_CP%;"C:\Program Files (x86)\H2\bin\h2-1.4.181.jar"
Then I restarted Squirrel SQL and everything was working as expected!
I'm listing the exact steps I followed to add the driver as even though Colin Bell has already given a good answer, without following the final step 4. I still couldn't get this to work.
Download http://www.h2database.com/automated/h2-latest.jar and save it somewhere, in my case ~/drivers/h2-latest.jar
Edit the existing h2 driver.
On the 'Extra Class Path' tab add the driver
Click 'List Drivers' - org.h2.Driver should appear in the 'Class Name' field (as detailed in the link from Colin's answer: http://www.squirrelsql.org/screenshots/driver.html)
I was missing the final step of clicking 'List Drivers' since it already had org.h2.Driver in the 'Class Name' before I tried to add it. But without this step it was still giving the error:
Could not find class org.h2.Driver in neither the Java class path nor the Extra class path of the H2 driver definition:
java.lang.ClassNotFoundException: org.h2.Driver
i can connect mysql with java using eclipse in a java application with these statements
String unicode = "?useUnicode=yes&characterEncoding=UTF-8";
Class.forName("com.mysql.jdbc.Driver");
con = (Connection) DriverManager.getConnection(
"jdbc:mysql://localhost:3306/ams-competation" + unicode,
username, password);
and it works good
but my problem is when i tried to connect to mysql with a server application i got this exception
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
what am i doing wrong?thank you all
Edit
i have added mysql-connector already
I think you have not included mysql drive jar in your web project.
put mysql-connector-java.. jar file in your web projects lib folder
for that you need to add the mysql-connector jar in the classpath.
This is because eclipse is not able to find the jar file you specified.
Hence put the jar file in the server`s lib directory
another way is to put jar file it in /WEB-INF/lib eclipse itself will notice it and get it.
Did you add the MySQL driver to the server?
It depends on the application server where the jar file is needed to be added:
Apache Tomcat: $CATALINA_HOME/common/lib
GlassFish server: GLASS_FISH_INSTALL_DIR\lib
Or add it the WEB-INF/lib folder of your web application
Try adding the mysql-connector-java-5.1.20-bin.jar file (downloadable from: http://dev.mysql.com/downloads/connector/j/ ), and restart the server.
Add the Connector/J jar file to the server's classpath (or lib folder)
add my sql connection jar file to your project. Its name will be something like "mysql-connector-java-5.1.13-bin.jar"
connect connector/J 8.0.11 with eclipse oxygen by following line of code.
Class.forName("com.mysql.cj.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/testing?autoReconnect=true&useSSL=false", "AF", "birru123");
Statement st = conn.createStatement();
I am new to SOAPUI and have been trying to do query and procedure testing using SOAPUI.
I went through the SOAPUI documentation on net however I am not able to establish an connection to my DB..
I have copied the mysql jar in the lib folder of SOAPUI.
The exception I get is
Tue Nov 08 12:54:51 IST 2011:ERROR:com.eviware.soapui.support.SoapUIException: Failed to init connection for drvr [com.mysql.jdbc.Driver], connectionString [jdbc:mysql://DB SERVER IP:PORT/DB NAMES?user=username&password=password]
Can anyone please tell me what is wrong...
Here are the steps of what I did in SOAPUI for this JDBC thing:-
> 1.New project.
> 2. Clock on New Project.
> 3.Go to JDBC Connections tab.
> 4. Add a new Data Connection.
> 5. Specified unique name.
> 6. selected driver as mysql:com.jdbc.driver
> 7.I can only see to mention host,port and DB.
> 8.Mentioned Host,Port and DB..
> 9.Tested the Connection.
> 10.Got the above mentioned excpetion...
Please help anyone...
You could try the following. I had the same problem once and the following was working for me:
Download the JAR for MySQL again. In my case it happened that the JAR itself was corrupt.
Copy the JAR to %soapUI Folder%\bin\ext
This worked perfectly fine for me!
Download the mySQL connector tar.gz file from here http://dev.mysql.com/downloads/connector/j/5.0.html
Copy it at \SmartBear\SoapUI-Pro-5.0.0\bin\ext path
Extract it and Restart the application
Test the connection again! :)
Driver jar must be in ext folder and you also need to register a driver before actually using it.
for example to register postgresql driver use :
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver("org.postgresql.Driver")
For me coping mysql jar in lib folder worked <%soapUI%/lib> and not <%soapUI%/bin/ext>
What worked for me:
Copy the ojdbc6.jar in lib and ext folders.
check your connections strings. It could be different.Are you trying to add using datasource? or script?
Remember to restart once you have downloaded the driver and included it in the directory.
I have written a code to check whether connection is successful or not.
But its giving error.
I have a oracle 10g express edition instsalled on my computer.
try{
String url="jdbc:oracle:thin:#//localhost:1521:XE";
String driver= "oracle.jdbc.driver.OracleDriver";
Class.forName(driver);
System.out.println(" Driver loaded ");
Connection con = DriverManager.getConnection(url,"system:,"manager");
System.out.println("Connection Successful");
} //catch block
The error given is:
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
Thanks for help.
you need to add oracle jdbc driver (jar) to your class path.
Looks like the JAR file containing the oracle.jdbc.driver.OracleDriver class is simply not on your classpath. Find it and fix that problem by adding the location (e.g., via the -cp option to java; the details of how to fix it will vary by the kind of application you're building).
Add ojdbc.jar in classpath.
Check this for How to Add JARs to Project Build Paths in Eclipse
You have to put the oracle_jdbc.jar file in the same folder of your code, or anywhere else and add that folder to your classpath.