GeeCON Prague 2014*
The moose likes JDBC and the fly likes java.sql.SQLException: No suitable driver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.SQLException: No suitable driver" Watch "java.sql.SQLException: No suitable driver" New topic
Author

java.sql.SQLException: No suitable driver

Shaji Kalidasan
Greenhorn

Joined: Oct 30, 2003
Posts: 9
Hi,

I am trying to connect my webapp to the DB2 database. I am using Websphere application server in linux box.I am using V8.1 of DB2 and WebSphere Application Server Version 5

I tried to configure the datasource(JDBC Provider) in two ways by using

1. User-defined JDBC Provider
2. DB2 Universal JDBC Driver Provider

ForUser-defined JDBC Provider I have set the following classpath

${DB2_JDBC_DRIVER_PATH}/db2java.zip

where the value for ${DB2_JDBC_DRIVER_PATH} is /opt/IBM/db2/V8.1/java

The implementation classname for this driver is com.ibm.db2.jcc.DB2ConnectionPoolDataSource

But, when I try to run my app I am getting the following error

Error java.sql.SQLException: java.lang.UnsatisfiedLinkError: Can't find library db2jdbc (libdb2jdbc.so) in sun.boot.library.path or java.library.path
sun.boot.library.path=/opt/WebSphere/AppServer/java/bin/../jre/bin
java.library.path=/opt/WebSphere/AppServer/java/bin/../jre/bin:/opt/WebSphere/AppServer/java/jre/bin/classic:/opt/WebSphere/AppServer/java/jre/bin:/opt/WebSphere/AppServer/bin:/opt/mqm/java/lib:/opt/wemps/lib:/usr/lib

For <bold>DB2 Universal JDBC Driver Provider</bold> I have set the following classpath

${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar
${UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cu.jar
${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cisuz.jar

where the value for ${DB2UNIVERSAL_JDBC_DRIVER_PATH}is /opt/IBM/db2/V8.1/java

The implementation classname for this driver is com.ibm.db2.jcc.DB2ConnectionPoolDataSource

But, when I try to run my app I am getting the following error

Error java.sql.SQLException: No suitable driver

Here is the sample code which I am using from the JSP page

Context initContext = new InitialContext();
DataSource ds = (DataSource)initContext.lookup("jdbc/ams");
Connection con = ds.getConnection();
//Class.forName("com.ibm.db2.jcc.DB2ConnectionPoolDataSource");
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
// Connection con;
//step 2 Creation of a connection thru JDBC Driver Instance
con = DriverManager.getConnection("jdbc b2:AMS_DB", "db2inst1","db2inst1");
//step 3 Creation of one or more statements using the RDBMS connection
Statement stmt = con.createStatement();
....
....

Can you please help me on this.

Thanking you in advance.

Sincerely,
Shaji Kalidasan
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42035
    
  64
Can't find library db2jdbc (libdb2jdbc.so) in sun.boot.library.path or java.library.path


Is that library in one of the two paths?


Ping & DNS - my free Android networking tools app
Michael Duffy
Ranch Hand

Joined: Oct 15, 2005
Posts: 163
Originally posted by Shaji Kalidasan:
[QB]Hi,

I am trying to connect my webapp to the DB2 database. I am using Websphere application server in linux box.I am using V8.1 of DB2 and WebSphere Application Server Version 5

I tried to configure the datasource(JDBC Provider) in two ways by using

1. User-defined JDBC Provider
2. DB2 Universal JDBC Driver Provider


Two thoughts:

(1) The link difficulty with the shared library occurs because you're not using a type IV JDBC driver. I'm sure there's a 100% Java driver for DB2. That will eliminate the need for a shared library link.

(2) I see "No suitable driver" error when the JVM has successfully loaded the driver class but I've made an error in the syntax for the connection URL. Check your syntax to eliminate that problem.

%


%
Alexander Krotov
Greenhorn

Joined: Feb 09, 2005
Posts: 9
I have the similiar problem.

I connect via type 4 driver. But my goal is to use type 2.
I have DB2 8.2 runtime client on my PC, DB2 8.2 personal on other.

I have DB2 alias:

---------------------------------------------------
db2 => LIST DATABASE DIRECTORY

System Database Directory

Number of entries in the directory = 1

Database 1 entry:

Database alias = RBCX
Database name = RBCX
Node name = DB2TCP15
Database release level = a.00
Comment =
Directory entry type = Remote
Authentication = SERVER
Catalog database partition number = -1
Alternate server hostname =
Alternate server port number =

---------------------------------------------------

I tested this:
db2 => connect to RBCX user db2admin

That works.

I:
- add db2java.zip into my classpath
- set connection url as jdbc b2:RBCX
- set jdbc driver class = COM.ibm.db2.jdbc.app.DB2Driver
- connect by jdbc 2 and obtain:

java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:563)
at java.sql.DriverManager.getConnection(DriverManager.java:194)

I cannot see, what's wrong.


Alex Krotov<br />SCEA, step I - 89%, II/III - 92%<br />Brainbench/"OO Concepts" - 4.31
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
You are running into this problem because there are two classpaths you are dealing with. You database driver needs to be in the Java classpath to compile, and your Web servers classpath for execution.

Cheers,


Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
Alexander Krotov
Greenhorn

Joined: Feb 09, 2005
Posts: 9
Hi Tom,

Thanks for fast response.
Please explain me, what does it mean "2 classpathes".

I test my connection without any container (you noticed about web container), just via POC (pure old console).
As I know, because jdbc driver classes are loaded dynamically, they need not be added in classpath while source code compilation.

I've read from several sources, that problem can be in connection url syntax and driver mismatch. To be honest, in this case to make mistake is a rather hard (but may be I did..but where?). To avoid any flaws like this I construct my classpath as you can see here (env.bat):
---------------------------------------------
@echo off

set APP_HOME=.
set APP=%APP_HOME%/jdbc-connect-test-1.0.jar
set APP_LAUNCHER_CLASS=com.infy.jdbc.JDBCRequestor
set LIB_HOME=%APP_HOME%/lib

@rem For DB2 7:
set DB2_LIB=%LIB_HOME%/db2java.zip

set DB2INSTANCE=C:/IBM/SQLLIB
set DB2_DRIVER_PATH=%DB2INSTANCE%/java/db2java.zip

@rem set PATH=%DB2INSTANCE%\bin;%PATH%

set PATH=%DB2INSTANCE%/bin

set XERCES=%LIB_HOME%/axerces.jar
set LOG=%LIB_HOME%/log4j-1.2.9.jar

set JAVA_HOME=C:\IBM\WebSphere\AppServer5.0\java

set JAVA=%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\jre\lib\rt.jar;
set CPATH=%APP_HOME%;%APP%;%LOG%;%DB2_LIB%;%XERCES%;%JAVA%
---------------------------------------------

I also set PATH myself as well.

I launch my connection test:

---------------------------------------------
@echo off
setLocal
call env.bat
%JAVA_HOME%\bin\java -cp %CPATH% %APP_LAUNCHER_CLASS%
endLocal
---------------------------------------------

May be I should set some env value, but which one, I don't catch.

If you can see some suspicious staff at these batch files, please let me know.

P.S. This testing app worked for many jdbc type 4 configs (oracle/mysql/sybase/derby/cloudscape/pointbase) without problems.
Alexander Krotov
Greenhorn

Joined: Feb 09, 2005
Posts: 9
OK, I found a solution myself, thanks to all.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30586
    
154

Alexander,
What was the solution?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Tim Jowers
Greenhorn

Joined: Feb 13, 2006
Posts: 5
db2jdbc.dll

PATH has path to sqllib but apparently not being parsed by IBM properly. Apparently the space between "Program Files" causes it to fail. Launch from sqllib\bin folder and it works. Oh, here's some code that helps but still really doesn't point out the problem:

try { Class driverClass = Class.forName( driver );
try {
Driver _driver = (Driver) driverClass.newInstance();
...

Found the answer in a post n a ng.
Shankar Kolinjavadi
Greenhorn

Joined: Mar 08, 2006
Posts: 1
Nothing's more frustrating than someone who asked for help in a forum - then finds a solution - tells every one he has solved the issue - but does not share how he solved it with the rest of the community.

I am wrestling with the same issue - a couple of minutes of time taken to post his solution - would have saved me days...
I will post the solution when I get there.

I am using the Spring Ibatis framework to get to DB2. I get an abstractMethodError when using the older db2 7.1 driver (on a gettype method on a resultset implementation) . When I switch to JDBC type4 driver - i get the "no Suitable Driver" error.
Alexander Krotov
Greenhorn

Joined: Feb 09, 2005
Posts: 9
==============
Nothing's more frustrating than someone who asked for help in a forum - then finds a solution - tells every one he has solved the issue - but does not share how he solved it with the rest of the community.
==============
Oh, I clearly see your point. As for me, if it was solution of this particular problem, I'd gladly shared it with anyone. But the goal of my work was not solve this particular task (connect to db2 7 by using db8 type2 or 4 drivers), but to find any means to connect db7 (client uses this version and it was even a bit stupid for me to try using db2 8 driver). Eventually I just installed db2 7 client, installed db2 7 server (forgot about db2 8), started using db2 7 driver and all simply worked. To explain this administrative (not technology) solutuion - I didn't see too many reasons. Sorry, if I mislead you.
prawin kumaar
Greenhorn

Joined: Feb 16, 2010
Posts: 1
Hi,

I want to connect to DB2 in remote machie through RFT in my local machine.

I have used the below code,

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import COM.ibm.db2.jdbc.app.DB2Driver;


public class DB2Connection {
/**
* Script Name : <b> DB2Connection</b>
* Description : Functional Test Script
* Original Host : WinNT Version 5.1 Build 2600 (S)
*
* @author Admin
*/

public Connection connection = null;
public ResultSet resultset = null;
public Statement statement = null;

public void connect() throws Exception
{
Driver driver = new COM.ibm.db2.jdbc.app.DB2Driver();
DriverManager.registerDriver(driver);
System.out.println("Driver Loaded Successfully ...");



connection = DriverManager.getConnection("jdbc:db2:<database name here>","<Usernamehere>", "<pwd here>");
System.out.println("Driver Loaded Next ...");
if (connection == null)
{
System.out.println("connection failed");
}
connection.setAutoCommit(true);
System.out.println("Successfully Connected to DB2...");

statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);



ResultSet rs = statement.executeQuery("<query here>");



System.out.println(rs.first());

//System.out.println(rs.getArray(1));


for (int i=1;i<15;i++) {
System.out.println(rs.getObject(i));
}


//System.out.println(rs.getArray("Address_line_one"));




System.out.println("Hi");


//statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
}

public ResultSet query(String arg) throws SQLException
{
try
{
statement = connection.createStatement
(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
//resultset = statement.executeQuery( Select * from <WCC>);
}catch (Exception ioe)
{
System.out.println("Query failed: " + arg);
ioe.printStackTrace();
}
return resultset;
}


public void close () throws Exception
{
if (connection != null)
{
try
{
connection.commit();
connection.close();
}catch (Exception e)
{
System.out.println("Problem in closing DB2 connection: " + e.getMessage());
}
connection = null;
}
}

public static void main(String args[])
{
DB2Connection db = new DB2Connection();
try {
db.connect();

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}



and I've included db2jcc and db2 licence jar files in the java -classpath
Still I am not able to connect to the database, I am geting the below error

"java.SQL.SQLException: java.lang.UnsatisfiedLinkError: db2jdbc (Not found in java.library.path)
at COM.ibm.db2.kdbc.app.DB2Driver.<init>(Unknown source)"


Can someone please help me on this.....



PraveeN
Charles Pham
Greenhorn

Joined: May 30, 2012
Posts: 1
This may be a little late for some of the previous posters, but here's for people who may be having problems with this in the future...

Don't use the driver in 'db2java.zip' file (COM.ibm.db2.jdbc.app.DB2Driver). This driver tries to load a C library file (probably for a Unix) environment.
So you probably need to set LD_LIBRARY_PATH and such.

Use (com.ibm.db2.jcc.DB2Driver) in 'db2cc.jar' instead.


 
GeeCON Prague 2014
 
subject: java.sql.SQLException: No suitable driver