Class [org.apache.derby.jdbc.ClientDriver] not found Exception [duplicate] - java

This question already has an answer here:
Class [org.apache.derby.jdbc.ClientDriver] not found. When trying to connect to db
(1 answer)
Closed 7 years ago.
![JAVADB_DRIVER_LABEL library missing][1]
I am trying to connect to a JavaDB through netbeans 8 IDE on Windows 7. i can connect it using the DB manager provided with netbeans in Services panel. But when trying to connect it through my code I get ClassNotFoundException for the org.apache.derby.jdbc.ClientDriver class.
I could not run the Apache tomcat server on my machine, so I am Using the Glassfish server 4 that comes with netbeans.
my code to connect to the DB is as follows:
String url = "jdbc:derby://localhost:1527/sample;UID=app;PWD=app";
Class.forName("org.apache.derby.jdbc.ClientDriver");
conn = DriverManager.getConnection(url);
This similar code worked with SQL server, MS Access.

Please add your jdbc driver to the classpath of your project. It should work.
Currently, the class loader is unable to load your driver class as it does it does not find it in the classpath

Download the version of Apache Derby you need from here. Extract the zip and you should get derbyclient.jar which has the class org.apache.derby.jdbc.ClientDriver.
FYI : If your application runs on JDK 1.6 or higher, then you do not need to explicitly load the EmbeddedDriver. In that environment, the driver loads automatically.

You need to add derbyclient.jar to your classpath. You can find this jar in the download package of derby from here. This jar contains your org.apache.derby.jdbc.ClientDriver.
For more information, see this answer : where is org.apache.derby.jdbc.ClientDriver?

Related

Java MySQL Exception - No suitable driver found [duplicate]

This question already has answers here:
No suitable driver found for 'jdbc:mysql://localhost:3306/mysql [duplicate]
(8 answers)
Closed 8 years ago.
I'm trying to connect my Java program to a database, but for some reason I'm getting an exception telling me there's No suitable driver found.
This is the code I use to connect:
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection connect = DriverManager.getConnection("jdbc:mysql//localhost:3307/miku");
PreparedStatement statement = connect.prepareStatement("SELECT * FROM users");
ResultSet result = statement.executeQuery();
Does anyone see what the problem is?
You need to add MySQL connector driver jar. Download it from here and add it to your classpath.
PS : If you are using Java 7 you don't even have to write Class.forName("com.mysql.jdbc.Driver");. it will automatically be loaded from the classpath. So just add your driver jar file to the classpath.
Just add mysql connector jar. If you using Netbeans right click on the Libraries folder on project and then add library. There is library called MySql JDBC Driver and add it.

Conflict between Netbeans IDE 8.0 and UCanAccess?

I have to define a new Driver in the Netbeans "Services" Tab
Services->Databases->Drivers->new Driver...
because I want use the "Entity Classes from Database"-Wizard in context with UCanAccess.
1st step: "new Driver" does work (only declaration ;-) )
Driver File(s): f:\WorkspaceNetbeans\MSAccessDB\lib\UCanAccess-2.0.4-bin\ucanaccess-2.0.4.jar
Driver Class: net.ucanaccess.jdbc.UcanaccessDriver
Name:msaccess
2nd step: "Connect using..."
JDBC URL: jdbc:ucanaccess://F:/WorkspaceNetbeans/MSAccessDB/data/Datenbank2.accdb
"User Name" and "Password" leave blank
The "Test Connection"-Button results in Error Message:
Cannot establish a connection to
jdbc:ucanaccess://F:\WorkspaceNetbeans\MSAccessDB\data\Datenbank2.accdb using
net.ucanaccess.jdbc.UcanaccessDriver (Could not initialize class
net.ucanaccess.jdbc.UcanaccessDriver)
I've got the newest ucanaccess from http://ucanaccess.sourceforge.net/site.html
ucanaccess-2.0.4.jar, commons-lang-2.6.jar, commons-logging-1.0.4.jar, hsqldb.jar, jackcess-2.0.3.jar in the Netbeans Classpath.
The old fashion way to connect via jdbc to ucanaccess works fine.
public static void main(String[] args) throws ClassNotFoundException, SQLException {
String connectString = "jdbc:ucanaccess://" + "f:/WorkspaceNetbeans/MSAccessDB/data/Datenbank2.accdb";
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection conn = DriverManager.getConnection(connectString, "", "");
conn.createStatement().execute("CREATE TABLE example1 (id COUNTER PRIMARY KEY,descr text(400), number numeric(12,3), date0 datetime) ");
}
The same connection string also works fine make DBeaver able to connect to the MSAccess db.
My set up:
Windows 7 Professional 64 bit
Microsoft Office 2013
NetBeans IDE 8.0
Java 1.8
The problem is similar to: "Conflict between JT400 and UCanAccess?" Conflict between JT400 and UCanAccess?
but the answers there don't help with my problem.
Any ideas to solve my problem?
UCanAccess 2.0.4.1 has been released, now you can configure UCanAccess as NetBeans service.
As explained in the UCanAccess web site (tab 'jdbc client tools') you have to:
-in the field Driver File(s), add ucanaccess.jar and all dependencies. I've upgraded the commons-logging in the UCanAccess distribution to the 1.1.1, so you can use that jar with NetBeans8.
-use the following pattern for the jdbc url:
jdbc:ucanaccess://;showschema=true
Showschema connection property must be setted to true.
I was wrong, it wasn't a tricky task but...
To establish the connection you have to list in the Driver File(s) :
ucanaccess-2.0.4.jar,
commons-lang-2.6.jar,
hsqldb.jar,
jackcess-2.0.3.jar
AND
a different version of commons-logging that you can find it in NetBeans:
NetBeans 8.0\ide\modules\org-apache-commons-logging.jar (the commons-logging in the UCanAccess distribution is in conflict with that used by NetBeans)
But unfortunatly, after establishing the connection, you won't be able to execute queries through this IDE, because of a trivial bug in the UcanaccessDatabaseMetadata which hasn't effect with the other IDE jdbc clients I tested (Openoffice, Libreoffice, DBeaver, Squirrel, SQLeo and so on) .
So, to do this, you have to wait some days (I think I'll post a patched Ucanaccess 2.0.4.1 next week). Also, I'll add a note about UCanAccess configuration as NetBeans service in the UCanAccess web site.

Unable to connect Oracle 11g via thin

I am trying to connect to Oracle 11g DB through my below java code, in an web application using Tomcat 4 server. ojdbc6.jar in Eclipse build path, but getting this below Error.
BUT when I tried this piece of same Java code in a Java file (public static void main()) and having ojdbc6.jar in Eclipse build path, it was able to connect to d DB, Very Strange!!
Then why this same code is not working in my web application??
Server: Tomacat 4
JDK Version: JDK 1.6
Java Code:
Class.forName("oracle.jdbc.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:#hostName:portNum:SID","user", "pass");
Getting this below Error:
java.lang.ArrayIndexOutOfBoundsException: 7
at oracle.security.o3logon.C0.r(C0)
at oracle.security.o3logon.C0.l(C0)
at oracle.security.o3logon.C1.c(C1)
at oracle.security.o3logon.O3LoginClientHelper.getEPasswd(O3LoginClientHelper)
at oracle.jdbc.ttc7.O3log.<init>(O3log.java:289)
at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:251)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:246)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:365)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:260)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
Since your standalone program is running correctly, it means your program runtime classpath is fine. However for Tomcat 4 its failing which raises a suspicion on the tomcat classpath. My guess is that since your tomcat is pretty old, it might be containing old driver class (may be classes12.jar or older ojdbc jar file in libraries of your tomcat (especially look into the $CATALINA_HOME/common/lib). If that is the case remove all other jars except ojbdc6 from your classpath. Also make sure your web application libraries do not contain the classes12.jar or older ojdbc jars.
Also you can try to use -verbose:class in your tomcat jvm startup to print the information from where the classes are loaded. This will however output lots of information in the log files.Search for the driver class and it will show you where this was loaded from.
Loaded oracle.jdbc.driver.OracleDriver from file: xxx.jar

Why is DB2 Type 4 JDBC Driver looking for native library db2jcct2?

I thought the Type 4 JDBC driver was pure Java and wouldn't require native libraries.
When I put db2jcc4.jar in the WEB-INF/lib directory of my Tomcat app packaged as a .war file, I get the following error when attempting to use the app: Got SQLException: com.ibm.db2.jcc.am.SqlException: [jcc][10389][12245][4.12.55] Failure in loading native library db2jcct2, java.lang.UnsatisfiedLinkError
The relevant application code is as follows and the exception is thrown due to the last line in the listing:
import com.ibm.db2.jcc.DB2SimpleDataSource;
// ...
DB2SimpleDataSource main_db2_data_source = new DB2SimpleDataSource();
main_db2_data_source.setUser(main_database_user);
main_db2_data_source.setPassword(main_database_password);
main_db2_data_source.setServerName(main_database_host);
try {
Integer main_database_port_integer = Integer.parseInt(main_database_port);
main_db2_data_source.setPortNumber(main_database_port_integer);
} catch (NumberFormatException exception) {
throw new WebException("...");
}
Connection main_connection = null;
try {
main_connection = main_db2_data_source.getConnection();
I suspect the problem is that you haven't told it to use the type 4 driver - the same jar file contains both type 4 and type 2 drivers, I believe.
Try:
main_db2_data_source.setDriverType(4);
The db2 driver needs another jar that includes the license.
This license controls the connection type. If you are going to use "db2 connect" to connect to a mainframe as an i series you should use the corresponding license. If you are going to connect to a Linux UNIX or Windows server, the license is included when you get the "Data server client for JDBC"
Also try this:
Goto Configure Build Path --> Libraries
--> JRE System Libraries
--> Native Library Location : Set this to %DB2HOME%/BIN
(which is where db2jcct2.dll is saved)
Recently i have faced this issue, when i was connecting to DB2 from Glassfish server. for this i have followed below steps and resolved this issue.
Please check it the below steps
step1) i have checked DB2 details in Domain.xml file.there i have seen only
username,pwd,databaseName,serverName ,portnumber, But i havent see DriverType.
Means Type of driver is 2 or 4.
2)for adding Type of driver i have logged into the Glassfish server admin console
Resources-->JDBC-->Connection pool -->our poolname --.add extra property
here i haved added as drivertype is 4.
Hence my problem has been solved
Thanks,
Ramaiah Pillala.

can oci driver for 11g (odbc5.jar) work with 10g client?

I need to connect to Oracle9,10 and 11 in my java application.The client will always be present where the app will be run and I want the app to just work with username,password and instance (specified in tnsnames.ora).Hence I would like oci drivers with a connection string of type : jdbc:oracle:oci:#testora .Im using the driver: oracle.jdbc.driver.OracleDriver.
I have a 10g client and am using jdk1.5. When I use the ojdbc14 jar from client lib path the app runs.
But if I use the ojdbc5 driver then the app fails with
Exception in thread "main" java.lang.UnsatisfiedLinkError: no ocijdbc11 in java.
library.path
exception.
What im looking for is a way to package a single jar(ojdbc5/ojdbc14) and a single driver which will use oci drivers to connect to the client that is present on local machine(9/10/11).This is the way I would prefer it.
If this is not possible can I search the unix box for oracle version,pick up the correct jar and then use it in classpath when invoking the app which is in jar format?
Thanks,
Fell
java.lang.UnsatisfiedLinkError: no ocijdbc11 in java.library.path
This means that you are missing a DLL (ocijdbc11.dll) in the Java library path. Make sure you have that DLL and start your program like this:
java -Djava.library.path=C:\mydirwiththedll com.mypackage.MyProgram
ojdbc5.jar is intended to work with jdk1.5.x either you are connecting to Oracle 10 or 11g shouldn't matter, ojdbc14.jar was intended for jdk1.4.x

Categories