By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,367 Members | 1,331 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,367 IT Pros & Developers. It's quick & easy.

Tomcat DB2 connection - No suitable driver

P: n/a
Hi,

I am trying to make a UBD DB2 7.2 connection using the Java
COM.ibm.db2.jdbc.app.DB2Driver via Tomcat 3.2.1 on Solaris (and also
on an AIX system with 3.3.1). I am attempting this either via JSP or
a servlet.

I have a separate java application that I can run from the command
line and as long as the user has the correct env variables:

DB2DIR=/opt/IBMdb2/V7.1
DB2INSTANCE=repowner
INSTHOME=/home/repowner

Then the connection is fine. I am using the same code to try and make
the connection via tomcat.

try
{
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
// next line is printed out
System.out.println(new java.util.Date().toString() + " DRIVER
FOUND.");
}
catch(ClassNotFoundException e)
{
System.out.println(new java.util.Date().toString() + " Error 1:
"+e);
}
String dbType="db2";
// String ip="10.0.0.185";
// String port="8790";
String dbName="ppreport";
String reason="testing db connection";
String userName="repowner";
String password="ilink1";
Connection con = null;

String url = "jdbc:db2:"+dbName;

boolean dbConnected = false;

try
{
System.out.println(new java.util.Date().toString() + " Connecting
to database URL = " + url + " for " + reason);
Enumeration e = DriverManager.getDrivers();
while (e.hasMoreElements()) {
Driver d = (Driver) e.nextElement();
// doesn't print anything here
System.out.println("driver is " + d.toString());
}
System.out.println("a1");
// gets to here and stops!
Driver d = DriverManager.getDriver(url);
System.out.println("a1.1"+d.toString());

con = DriverManager.getConnection(url, userName, password);

java.sql.Statement stmt = con.createStatement();
System.out.println("SETTING SCHEMA TO "+dbName);
try {
stmt.execute("SET SCHEMA = "+dbName);
System.out.println("SCHEMA SET.");
}
catch (Exception ex) {
System.out.println("Error Setting Schema:"+ex);
}

System.out.println(new java.util.Date().toString() + " Database
connection established.XX");
dbConnected = true;
}
catch(Exception e)
{
System.out.println(new java.util.Date().toString() + " Failed to
connect, reason : \n" + e);

}

However via tomcat the driver cannot be loaded by the class loader.
The class is found, but not loaded. The error I receive is
"java.sql.SQLException: No suitable driver"

I have placed the db2java.zip (renamed as db2java.jar) in several
places to try and solve the problem (restarting Tomcat each time) but
to no avail:

/usr/apache/tomcat/common/lib/db2java.jar
..../WEB-INF/classes/db2java.jar

I have read many posts, but I can't understand how the driver will
know the correct env variables even if the class is loaded.

Any help would be much appreciated!!!

Thanks!
Andy.
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
The attempted connection will throw the error you are seeing if the
class has not been loaded first. The most common source of this is if
the driver class you specified is not found in your CLASSPATH. On
issuing the Class.forName() call, the java classloader will search the
CLASSPATH for a class with the given name, and load it into memory. An
exception is not thrown here unless you try to create a newInstance() of
the class.

Thus, you'll need to modify your CLASSPATH to include the location of
the DB2 Java drivers.

Andrew Johnson wrote:
Hi,

I am trying to make a UBD DB2 7.2 connection using the Java
COM.ibm.db2.jdbc.app.DB2Driver via Tomcat 3.2.1 on Solaris (and also
on an AIX system with 3.3.1). I am attempting this either via JSP or
a servlet.

I have a separate java application that I can run from the command
line and as long as the user has the correct env variables:

DB2DIR=/opt/IBMdb2/V7.1
DB2INSTANCE=repowner
INSTHOME=/home/repowner

Then the connection is fine. I am using the same code to try and make
the connection via tomcat.

try
{
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
// next line is printed out
System.out.println(new java.util.Date().toString() + " DRIVER
FOUND.");
}
catch(ClassNotFoundException e)
{
System.out.println(new java.util.Date().toString() + " Error 1:
"+e);
}
String dbType="db2";
// String ip="10.0.0.185";
// String port="8790";
String dbName="ppreport";
String reason="testing db connection";
String userName="repowner";
String password="ilink1";
Connection con = null;

String url = "jdbc:db2:"+dbName;

boolean dbConnected = false;

try
{
System.out.println(new java.util.Date().toString() + " Connecting
to database URL = " + url + " for " + reason);
Enumeration e = DriverManager.getDrivers();
while (e.hasMoreElements()) {
Driver d = (Driver) e.nextElement();
// doesn't print anything here
System.out.println("driver is " + d.toString());
}
System.out.println("a1");
// gets to here and stops!
Driver d = DriverManager.getDriver(url);
System.out.println("a1.1"+d.toString());

con = DriverManager.getConnection(url, userName, password);

java.sql.Statement stmt = con.createStatement();
System.out.println("SETTING SCHEMA TO "+dbName);
try {
stmt.execute("SET SCHEMA = "+dbName);
System.out.println("SCHEMA SET.");
}
catch (Exception ex) {
System.out.println("Error Setting Schema:"+ex);
}

System.out.println(new java.util.Date().toString() + " Database
connection established.XX");
dbConnected = true;
}
catch(Exception e)
{
System.out.println(new java.util.Date().toString() + " Failed to
connect, reason : \n" + e);

}

However via tomcat the driver cannot be loaded by the class loader.
The class is found, but not loaded. The error I receive is
"java.sql.SQLException: No suitable driver"

I have placed the db2java.zip (renamed as db2java.jar) in several
places to try and solve the problem (restarting Tomcat each time) but
to no avail:

/usr/apache/tomcat/common/lib/db2java.jar
.../WEB-INF/classes/db2java.jar

I have read many posts, but I can't understand how the driver will
know the correct env variables even if the class is loaded.

Any help would be much appreciated!!!

Thanks!
Andy.

Nov 12 '05 #2

P: n/a
I mean to say "... if the driver class has not been loaded first" in the
first sentence.

Andrew Johnson wrote:
Hi,

I am trying to make a UBD DB2 7.2 connection using the Java
COM.ibm.db2.jdbc.app.DB2Driver via Tomcat 3.2.1 on Solaris (and also
on an AIX system with 3.3.1). I am attempting this either via JSP or
a servlet.

I have a separate java application that I can run from the command
line and as long as the user has the correct env variables:

DB2DIR=/opt/IBMdb2/V7.1
DB2INSTANCE=repowner
INSTHOME=/home/repowner

Then the connection is fine. I am using the same code to try and make
the connection via tomcat.

try
{
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
// next line is printed out
System.out.println(new java.util.Date().toString() + " DRIVER
FOUND.");
}
catch(ClassNotFoundException e)
{
System.out.println(new java.util.Date().toString() + " Error 1:
"+e);
}
String dbType="db2";
// String ip="10.0.0.185";
// String port="8790";
String dbName="ppreport";
String reason="testing db connection";
String userName="repowner";
String password="ilink1";
Connection con = null;

String url = "jdbc:db2:"+dbName;

boolean dbConnected = false;

try
{
System.out.println(new java.util.Date().toString() + " Connecting
to database URL = " + url + " for " + reason);
Enumeration e = DriverManager.getDrivers();
while (e.hasMoreElements()) {
Driver d = (Driver) e.nextElement();
// doesn't print anything here
System.out.println("driver is " + d.toString());
}
System.out.println("a1");
// gets to here and stops!
Driver d = DriverManager.getDriver(url);
System.out.println("a1.1"+d.toString());

con = DriverManager.getConnection(url, userName, password);

java.sql.Statement stmt = con.createStatement();
System.out.println("SETTING SCHEMA TO "+dbName);
try {
stmt.execute("SET SCHEMA = "+dbName);
System.out.println("SCHEMA SET.");
}
catch (Exception ex) {
System.out.println("Error Setting Schema:"+ex);
}

System.out.println(new java.util.Date().toString() + " Database
connection established.XX");
dbConnected = true;
}
catch(Exception e)
{
System.out.println(new java.util.Date().toString() + " Failed to
connect, reason : \n" + e);

}

However via tomcat the driver cannot be loaded by the class loader.
The class is found, but not loaded. The error I receive is
"java.sql.SQLException: No suitable driver"

I have placed the db2java.zip (renamed as db2java.jar) in several
places to try and solve the problem (restarting Tomcat each time) but
to no avail:

/usr/apache/tomcat/common/lib/db2java.jar
.../WEB-INF/classes/db2java.jar

I have read many posts, but I can't understand how the driver will
know the correct env variables even if the class is loaded.

Any help would be much appreciated!!!

Thanks!
Andy.

Nov 12 '05 #3

P: n/a
Actually this message means that your database url
String url = "jdbc:db2:"+dbName;
does not match all already loaded drivers.
That's all.
In other words your driver COM.ibm.db2.jdbc.app.DB2Driver does not
recognize url
"jdbc:db2:ppreport"

I don't like IBM for their documentation. It took a year for me to
understand what they want when I tried to connect to DB2 on mainframe. So,
I really don't know what your driver wants. Try documnetation or examples
(if you have them :)))

How do you connect to your database wothout java? DB2 Connect? Local
instance?

Try another ways like this:
"jdbc:inetdb2:127.0.0.1:50000?database=pprepor t",
//"jdbc:db2://127.0.0.1:50000/ppreport",
//"jdbc:db2:127.0.0.1:50000:ppreport",
//"jdbc:db2:ppreport",
Alex Kizub.

Andrew Johnson wrote:
Hi,

I am trying to make a UBD DB2 7.2 connection using the Java
COM.ibm.db2.jdbc.app.DB2Driver via Tomcat 3.2.1 on Solaris (and also
on an AIX system with 3.3.1). I am attempting this either via JSP or
a servlet.

I have a separate java application that I can run from the command
line and as long as the user has the correct env variables:

DB2DIR=/opt/IBMdb2/V7.1
DB2INSTANCE=repowner
INSTHOME=/home/repowner

Then the connection is fine. I am using the same code to try and make
the connection via tomcat.

try
{
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
// next line is printed out
System.out.println(new java.util.Date().toString() + " DRIVER
FOUND.");
}
catch(ClassNotFoundException e)
{
System.out.println(new java.util.Date().toString() + " Error 1:
"+e);
}
String dbType="db2";
// String ip="10.0.0.185";
// String port="8790";
String dbName="ppreport";
String reason="testing db connection";
String userName="repowner";
String password="ilink1";
Connection con = null;

String url = "jdbc:db2:"+dbName;

boolean dbConnected = false;

try
{
System.out.println(new java.util.Date().toString() + " Connecting
to database URL = " + url + " for " + reason);
Enumeration e = DriverManager.getDrivers();
while (e.hasMoreElements()) {
Driver d = (Driver) e.nextElement();
// doesn't print anything here
System.out.println("driver is " + d.toString());
}
System.out.println("a1");
// gets to here and stops!
Driver d = DriverManager.getDriver(url);
System.out.println("a1.1"+d.toString());

con = DriverManager.getConnection(url, userName, password);

java.sql.Statement stmt = con.createStatement();
System.out.println("SETTING SCHEMA TO "+dbName);
try {
stmt.execute("SET SCHEMA = "+dbName);
System.out.println("SCHEMA SET.");
}
catch (Exception ex) {
System.out.println("Error Setting Schema:"+ex);
}

System.out.println(new java.util.Date().toString() + " Database
connection established.XX");
dbConnected = true;
}
catch(Exception e)
{
System.out.println(new java.util.Date().toString() + " Failed to
connect, reason : \n" + e);

}

However via tomcat the driver cannot be loaded by the class loader.
The class is found, but not loaded. The error I receive is
"java.sql.SQLException: No suitable driver"

I have placed the db2java.zip (renamed as db2java.jar) in several
places to try and solve the problem (restarting Tomcat each time) but
to no avail:

/usr/apache/tomcat/common/lib/db2java.jar
.../WEB-INF/classes/db2java.jar

I have read many posts, but I can't understand how the driver will
know the correct env variables even if the class is loaded.

Any help would be much appreciated!!!

Thanks!
Andy.


Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.