• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.sql.SQLException: No suitable driver

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

%
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Alexander Krotov
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I found a solution myself, thanks to all.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alexander,
What was the solution?
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
==============
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I'm developing using Eclipse at Windows.
I use the type 2 driver, driver [COM.ibm.db2.jdbc.app.DB2Driver], URL jdbc:db2:<db>. It's a legacy system, so no options there.

I was refactoring my code and I simply copied the working [db2java.zip] to a different directory, added it to the classpath, etc (I work professionally with java for 15 years, I have 3 certificates, I spent a fair amount of time on this, so I know I did it correctly), and I started getting the [No suitable driver found for jdbc:db2:<db>] error.
So the code was the same, the zip/jar with the driver was the same (I did a binary comparison), and the parameters were the same (URL / user id / passwd).

Out of curiosity I tried Charles suggestion to use the jcc driver. I could get a connection, I could execute some delete statements but simple selects were failing, so I reverted the change but tried something still based on Charles comment [This driver tries to load a C library file (probably for a Unix) environment]. I remembered that I got the zip/jar from the production environment, which runs AIX. I went after my local machine environment variables to see if could find any LD_LIBRARY_PATH or something like that (I never heard of those), and I noticed that my Windows DB2 installation (v9.7) was there at the classpath:
C:\PROGRA~1\IBM\SQLLIB\java\db2java.zip;

I simply removed my refactored [db2java.zip] and replaced it by a copy of the one from my local DB2 installation, and it started working fine (I copied it from my installation directory to my local projects directory).
So this is an alternative solution I think.
But I still don't understand some aspects of this matter:
- how my original (before the refactoring) AIX [db2java.zip] was working without problems, and my copy of [db2java.zip] was not (this sounds like a PATH problem, although I inspected thoroughly my Windows environment variables and didn't find a clue);
- if the [db2java.zip] really needs some external PATH config to work, why did my copy worked fine, since it is not referred at any Windows environment variable.
go figure...

Thank you all for this discussion! Although the solutions proposed didn't solve my problem directly, they provided some ideas to reach this alternative solution.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic