Now just insert the above into the servlet.....obviously make sure that the DB itself is running correctly first:)
Have fun:)
Main Topics
Browse All TopicsOk here we go.
I have had a ton of problems with tomcat and i now want to use my java servlet to connect to a DB2 database. All i want to do is to display a list of names from the "students" table in the database. The field is "firstname". The name of the database is "books" password is "passwd".
Please reply with all of the steps necessary to get this servlet working. Thank you in advance for your time.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Here's my version using DB connection pooling and JNDI
Get the following packages from
http://jakarta.apache.org/
commons-dbcp.jar
commons-pool.jar
commons-collections.jar
These provide the connection pool functionality. Copy
the jars to $CATALINA_HOME/common/lib.
Copy the DB2 driver jar to the same directory. On my
machine the DB2 instance is called db2inst1:
cp ~db2inst1/sqllib/java12/db
Note the extension .jar in the copied file. This is important!
Now configure the datasource for tomcat. Edit $CATALINA_HOME/conf/server
to the DefaultContext element:
<Resource name="jdbc/db2ds"
auth="Container"
type="javax.sql.DataSource
<ResourceParams name="jdbc/db2ds" >
<parameter>
<name>factory</name>
<value>org.apache.commons.
</parameter>
<parameter>
<name>maxActive</name>
<value>10</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>3</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>username</name>
<value>db2inst1</value>
</parameter>
<parameter>
<name>password</name>
<value>db2inst1</value>
</parameter>
<parameter>
<name>driverClassName</nam
<value>COM.ibm.db2.jdbc.ap
</parameter>
<parameter>
<name>url</name>
<value>jdbc:db2:wasrepos</
</parameter>
</ResourceParams>
This creates a datasource named "jdbc/db2ds" which connects
to the database catalogued as WASREPOS using the
the user db2inst1 and the password db2inst1.
Now code something which uses this datasource, e.g.
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.*;
import javax.sql.*;
import java.sql.Connection;
import java.sql.SQLException;
public class DSTestServlet extends HttpServlet {
public void doGet(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException {
String dsName = req.getParameter("ds");
PrintWriter out = res.getWriter();
res.setContentType("text/h
out.println("<html>\n<head
out.println("<body style=\"background-color: white;\">");
if ( dsName == null ) {
out.println("<h1>Parameter
} else {
try {
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("j
DataSource ds = (DataSource)envCtx.lookup(
Connection conn = ds.getConnection();
out.println("<h1>Successfu
"</h1>");
conn.close();
out.println("<h1>Successfu
"</h1>");
}
catch (SQLException e) {
out.println("<h1>Connect failed: " + e + "</h1>");
}
catch (NamingException e) {
out.println("<h1>NamingExc
": " + e);
}
catch (InterruptedException e) { }
}
out.println("</body>\n</ht
out.close();
}
}
Compile it and install it (i.e create an entry in
the appropriate web.xml for it).
If you haven't done so already, set the DB2 environment
variables. On my machine: . ~db2inst1/sqllib/db2profil
(This is UNIX specific.On Win you'd open a DB2 command
window). If you are on Linux: do an export LD_ASSUME_KERNEL=2.2.5. The DB2 "app" JDBC-driver behaves strange, otherwise.
Restart Tomcat.
Assuming that the DSTestServlet has been deployed
under the context "myapp", you should now be
able to access it and tell it to use the datasource
name "jdbc/db2ds" using: http://localhost:8080/DSTe
I've tested this setup using Tomcat 4.0.3, DB2 7.2 on
RH Linux 7.2.
If you'd rather use the "net" driver than the "app" driver,
replace the driverClassName in server.xml by
COM.ibm.db2.jdbc.net.DB2Dr
jdbc:db2://localhost:4777/
the DB2 java daemon on the DB server machine,. if you
are using the "net" driver: db2jstrt 4777
/**
* This is the code for a servlet i want it to connect to our database. We have read that the driver that is specified is included in the very recent version of Java SDK we have installed. If we can work with that one it would be great. Please advise exactly how to alter the code and do anything else needed. Thank you very much.. sorry about the long delay between posts.. been very busy.
* Creation date: (12/20/2002 9:18:35 AM)
* @author: BATMAN
* This servlet will connect to our DB2 database and display the first and last name of each student in the students table
* Remember: If you compile a servlet and then run it, then want to make changes, you will have to rename the .java file and
* recompile the servlet
*/
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;
import java.sql.*;
public class DB2 extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doPost(request,response);
}
public void doPost(HttpServletRequest request,HttpServletRespons
{
String usr = "Admin"; //This will need to change
String passwd = ""; //This will need to change
PrintWriter out = response.getWriter();
String FIRSTNAME,LASTNAME;
try
{
Class.forName("com.ibm.DB2
Connection con = DriverManager.getConnectio
Statement s = con.createStatement();
String sql = "SELECT * FROM Students";
ResultSet rs = s.executeQuery(sql);
while (rs.next())
{
FIRSTNAME = rs.getString("FIRSTNAME");
LASTNAME = rs.getString("LASTNAME");
out.println(FIRSTNAME + " " + LASTNAME + "<BR>");
}
rs.close();
s.close();
con.close();
}
catch (ClassNotFoundException e)
{
System.out.println(e.toStr
}
catch (SQLException e)
{
System.out.println(e.toStr
}
catch (Exception e)
{
System.out.println(e.toStr
}
}
}
Using the setup I described in my previous comment
you'll need to do the following:
The resource definition in server.xml would be (adjust
the 'password' parameter to the correct value):
<Resource name="jdbc/PrototypeBooks"
auth="Container"
type="javax.sql.DataSource
<ResourceParams name="jdbc/PrototypeBooks"
<parameter>
<name>factory</name>
<value>org.apache.commons.
</parameter>
<parameter>
<name>maxActive</name>
<value>10</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>3</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>username</name>
<value>Admin</value>
</parameter>
<parameter>
<name>password</name>
<value>whatever_you_choose
</parameter>
<parameter>
<name>driverClassName</nam
<value>COM.ibm.db2.jdbc.ap
</parameter>
<parameter>
<name>url</name>
<value>jdbc:db2:PrototypeB
</parameter>
</ResourceParams>
/**
* This is the code for a servlet i want it to connect to our database. We have read that the driver that is specified is included in the very recent version of Java SDK we have installed. If we can work with that one it would be great. Please advise exactly how to alter the code and do anything else needed. Thank you very much.. sorry about the long delay between posts.. been very busy.
* Creation date: (12/20/2002 9:18:35 AM)
* @author: BATMAN
* This servlet will connect to our DB2 database and display the first and last name of each student in the students table
* Remember: If you compile a servlet and then run it, then want to make changes, you will have to rename the .java file and
* recompile the servlet
*/
import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.*;
import java.util.*;
import java.io.*;
import javax.sql.*;
import java.sql.*;
public class DB2 extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doPost(request,response);
}
public void doPost(HttpServletRequest request,HttpServletRespons
{
PrintWriter out = response.getWriter();
String FIRSTNAME,LASTNAME;
out.println("<html>\n<head
"Student Names</title>" +
"\n</head>\n<body>");
try
{
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("j
DataSource ds = (DataSource)envCtx.lookup(
Connection con = ds.getConnection();
Statement s = con.createStatement();
String sql = "SELECT * FROM Students";
ResultSet rs = s.executeQuery(sql);
while (rs.next())
{
FIRSTNAME = rs.getString("FIRSTNAME");
LASTNAME = rs.getString("LASTNAME");
out.println(FIRSTNAME + " " + LASTNAME + "<BR>");
}
rs.close();
s.close();
con.close();
}
catch (NamingException e)
{
out.println("<h1>Failed to resolve datasource</h1>\n<pre>");
e.printStackTrace(out);
out.println("</pre>");
}
catch (SQLException e)
{
out.println("<h1>SQL exception</h1>\n<pre>");
e.printStackTrace(out);
out.println("</pre>");
}
catch (Exception e)
{
out.println("<h1>General exception</h1>\n<pre>");
e.printStackTrace(out);
out.println("</pre>");
}
out.println("</body>\n</ht
}
}
It means that the servlet couldn't find the
resource named "jdbc/PrototypeBooks" in the JNDI.
This could have several reasons. One of these
could be that the connection pool had a problem.
The server logs could have some pointers.
Could you post a listing of $CATALINA_HOME/common/lib and
the server.xml? This is just to make sure that on
the installation and configuration side everything is
OK.
contents of common/lib
activation.jar db2java.jar mail.jar
ant.jar jasper-compiler.jar naming-common.jar
commons-collections.jar jasper-runtime.jar naming-factory.jar
commons-dbcp.jar jdbc2_0-stdext.jar naming-resources.jar
commons-logging-api.jar jndi.jar servlet.jar
commons-pool.jar jta.jar
server.xml file
<!-- Example Server Configuration File -->
<!-- Note that component elements are nested corresponding to their
parent-child relationships with each other -->
<!-- A "Server" is a singleton element that represents the entire JVM,
which may contain one or more "Service" instances. The Server
listens for a shutdown command on the indicated port.
Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" or "Loggers" at this level.
-->
<Server port="8005" shutdown="SHUTDOWN" debug="0">
<!-- Uncomment these entries to enable JMX MBeans support -->
<Listener className="org.apache.cata
debug="0"/>
<Listener className="org.apache.cata
debug="0"/>
<!-- Global JNDI resources -->
<GlobalNamingResources>
<!-- Test entry for demonstration purposes -->
<Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users -->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.
description="User database that can be updated and saved">
</Resource>
<ResourceParams name="UserDatabase">
<parameter>
<name>factory</name>
<value>org.apache.catalina
</parameter>
<parameter>
<name>pathname</name>
<value>conf/tomcat-users.x
</parameter>
</ResourceParams>
</GlobalNamingResources>
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" (and therefore the web applications visible
within that Container). Normally, that Container is an "Engine",
but this is not required.
Note: A "Service" is not itself a "Container", so you may not
define subcomponents such as "Valves" or "Loggers" at this level.
-->
<!-- Define the Tomcat Stand-Alone Service -->
<Service name="Tomcat-Standalone">
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Each Connector passes requests on to the
associated "Container" (normally an Engine) for processing.
By default, a non-SSL HTTP/1.1 Connector is established on port 8080.
You can also enable an SSL HTTP/1.1 Connector on port 8443 by
following the instructions below and uncommenting the second Connector
entry. SSL support requires the following steps (see the SSL Config
HOWTO in the Tomcat 4.0 documentation bundle for more detailed
instructions):
* Download and install JSSE 1.0.2 or later, and put the JAR files
into "$JAVA_HOME/jre/lib/ext".
* Execute:
%JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA (Windows)
$JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA (Unix)
with a password value of "changeit" for both the certificate and
the keystore itself.
By default, DNS lookups are enabled when a web application calls
request.getRemoteHost(). This can have an adverse impact on
performance, so you can disable it by setting the
"enableLookups" attribute to "false". When DNS lookups are disabled,
request.getRemoteHost() will return the String version of the
IP address of the remote client.
-->
<!-- Define a non-SSL Coyote HTTP/1.1 Connector on port 8080 -->
<Connector className="org.apache.coyo
port="80" minProcessors="5" maxProcessors="75"
enableLookups="true" redirectPort="8443"
acceptCount="10" debug="0" connectionTimeout="20000"
useURIValidationHack="fals
<!-- Note : To disable connection timeouts, set connectionTimeout value
to -1 -->
<!-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 -->
<!--
<Connector className="org.apache.coyo
port="8443" minProcessors="5" maxProcessors="75"
enableLookups="true"
acceptCount="10" debug="0" scheme="https" secure="true"
useURIValidationHack="fals
<Factory className="org.apache.coyo
clientAuth="false" protocol="TLS" />
</Connector>
-->
<!-- Define a Coyote/JK2 AJP 1.3 Connector on port 8009 -->
<Connector className="org.apache.coyo
port="8009" minProcessors="5" maxProcessors="75"
enableLookups="true" redirectPort="8443"
acceptCount="10" debug="0" connectionTimeout="20000"
useURIValidationHack="fals
protocolHandlerClassName="
<!-- Define an AJP 1.3 Connector on port 8009 -->
<!--
<Connector className="org.apache.ajp.
port="8009" minProcessors="5" maxProcessors="75"
acceptCount="10" debug="0"/>
-->
<!-- Define a Proxied HTTP/1.1 Connector on port 8082 -->
<!-- See proxy documentation for more information about using this. -->
<!--
<Connector className="org.apache.coyo
port="8082" minProcessors="5" maxProcessors="75"
enableLookups="true"
acceptCount="10" debug="0" connectionTimeout="20000"
proxyPort="80" useURIValidationHack="fals
-->
<!-- Define a non-SSL legacy HTTP/1.1 Test Connector on port 8083 -->
<!--
<Connector className="org.apache.cata
port="8083" minProcessors="5" maxProcessors="75"
enableLookups="true" redirectPort="8443"
acceptCount="10" debug="0" />
-->
<!-- Define a non-SSL HTTP/1.0 Test Connector on port 8084 -->
<!--
<Connector className="org.apache.cata
port="8084" minProcessors="5" maxProcessors="75"
enableLookups="true" redirectPort="8443"
acceptCount="10" debug="0" />
-->
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host). -->
<!-- Define the top level container in our container hierarchy -->
<Engine name="Standalone" defaultHost="localhost" debug="0">
<!-- The request dumper valve dumps useful debugging information about
the request headers and cookies that were received, and the response
headers and cookies that were sent, for all requests received by
this instance of Tomcat. If you care only about requests to a
particular virtual host, or a particular application, nest this
element inside the corresponding <Host> or <Context> entry instead.
For a similar mechanism that is portable to all Servlet 2.3
containers, check out the "RequestDumperFilter" Filter in the
example application (the source for this filter may be found in
"$CATALINA_HOME/webapps/ex
Request dumping is disabled by default. Uncomment the following
element to enable it. -->
<!--
<Valve className="org.apache.cata
-->
<!-- Global logger unless overridden at lower levels -->
<Logger className="org.apache.cata
prefix="catalina_log." suffix=".txt"
timestamp="true"/>
<!-- Because this Realm is here, an instance will be shared globally -->
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.cata
debug="0" resourceName="UserDatabase
<!-- Comment out the old realm but leave here for now in case we
need to go back quickly -->
<!--
<Realm className="org.apache.cata
-->
<!-- Replace the above Realm with one of the following to get a Realm
stored in a database and accessed via JDBC -->
<!--
<Realm className="org.apache.cata
driverName="org.gjt.mm.mys
connectionURL="jdbc:mysql:
connectionName="test" connectionPassword="test"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles"
-->
<!--
<Realm className="org.apache.cata
driverName="oracle.jdbc.dr
connectionURL="jdbc:oracle
connectionName="scott" connectionPassword="tiger"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles"
-->
<!--
<Realm className="org.apache.cata
driverName="sun.jdbc.odbc.
connectionURL="jdbc:odbc:C
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles"
-->
<!-- Define the default virtual host -->
<Host name="localhost" debug="0" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- Normally, users must authenticate themselves to each web app
individually. Uncomment the following entry if you would like
a user to be authenticated the first time they encounter a
resource protected by a security constraint, and then have that
user identity maintained across *all* web applications contained
in this virtual host. -->
<!--
<Valve className="org.apache.cata
debug="0"/>
-->
<!-- Access log processes all requests for this virtual host. By
default, log files are created in the "logs" directory relative to
$CATALINA_HOME. If you wish, you can specify a different
directory with the "directory" attribute. Specify either a relative
(to $CATALINA_HOME) or absolute path to the desired directory.
-->
<!--
<Valve className="org.apache.cata
directory="logs" prefix="localhost_access_l
pattern="common" resolveHosts="false"/>
-->
<!-- Logger shared by all Contexts related to this virtual host. By
default (when using FileLogger), log files are created in the "logs"
directory relative to $CATALINA_HOME. If you wish, you can specify
a different directory with the "directory" attribute. Specify either a
relative (to $CATALINA_HOME) or absolute path to the desired
directory.-->
<Logger className="org.apache.cata
directory="logs" prefix="localhost_log." suffix=".txt"
timestamp="true"/>
<!-- Define properties for each web application. This is only needed
if you want to set non-default properties, or have web application
document roots in places other than the virtual host's appBase
directory. -->
<!-- Tomcat Root Context -->
<Context path="" docBase="ROOT" debug="0">
<Resource name="jdbc/PrototypeBooks"
auth="Container"
type="javax.sql.DataSource
<ResourceParams name="jdbc/PrototypeBooks"
<parameter>
<name>factory</name>
<value>org.apache.commons.
</parameter>
<parameter>
<name>maxActive</name>
<value>10</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>3</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>username</name>
<value>techno</value>
</parameter>
<parameter>
<name>password</name>
<value>gabbo</value>
</parameter>
<parameter>
<name>driverClassName</nam
<value>COM.ibm.db2.jdbc.ap
</parameter>
<parameter>
<name>url</name>
<value>jdbc:db2:bookstr</v
</parameter>
</ResourceParams>
</Context>
<!-- Tomcat MyApp Context -->
<Context path="/MyApp" docBase="MyApp" debug="0" reloadable="true"></Contex
<!-- Tomcat Examples Context -->
<Context path="/examples" docBase="examples" debug="0" reloadable="true" crossContext="true">
<Logger className="org.apache.cata
prefix="localhost_examples
timestamp="true"/>
<Ejb name="ejb/EmplRecord" type="Entity"
home="com.wombat.empl.Empl
remote="com.wombat.empl.Em
<!-- If you wanted the examples app to be able to edit the
user database, you would uncomment the following entry.
Of course, you would want to enable security on the
application as well, so this is not done by default!
The database object could be accessed like this:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/
UserDatabase database =
(UserDatabase) envCtx.lookup("userDatabas
-->
<!--
<ResourceLink name="userDatabase" global="UserDatabase"
type="org.apache.catalina.
-->
<!-- PersistentManager: Uncomment the section below to test Persistent
Sessions.
saveOnRestart: If true, all active sessions will be saved
to the Store when Catalina is shutdown, regardless of
other settings. All Sessions found in the Store will be
loaded on startup. Sessions past their expiration are
ignored in both cases.
maxActiveSessions: If 0 or greater, having too many active
sessions will result in some being swapped out. minIdleSwap
limits this. -1 means unlimited sessions are allowed.
0 means sessions will almost always be swapped out after
use - this will be noticeably slow for your users.
minIdleSwap: Sessions must be idle for at least this long
(in seconds) before they will be swapped out due to
maxActiveSessions. This avoids thrashing when the site is
highly active. -1 or 0 means there is no minimum - sessions
can be swapped out at any time.
maxIdleSwap: Sessions will be swapped out if idle for this
long (in seconds). If minIdleSwap is higher, then it will
override this. This isn't exact: it is checked periodically.
-1 means sessions won't be swapped out for this reason,
although they may be swapped out for maxActiveSessions.
If set to >= 0, guarantees that all sessions found in the
Store will be loaded on startup.
maxIdleBackup: Sessions will be backed up (saved to the Store,
but left in active memory) if idle for this long (in seconds),
and all sessions found in the Store will be loaded on startup.
If set to -1 sessions will not be backed up, 0 means they
should be backed up shortly after being used.
To clear sessions from the Store, set maxActiveSessions, maxIdleSwap,
and minIdleBackup all to -1, saveOnRestart to false, then restart
Catalina.
-->
<!--
<Manager className="org.apache.cata
debug="0"
saveOnRestart="true"
maxActiveSessions="-1"
minIdleSwap="-1"
maxIdleSwap="-1"
maxIdleBackup="-1">
<Store className="org.apache.cata
</Manager>
-->
<Environment name="maxExemptions" type="java.lang.Integer"
value="15"/>
<Parameter name="context.param.name" value="context.param.value
override="false"/>
<Resource name="jdbc/EmployeeAppDb" auth="SERVLET"
type="javax.sql.DataSource
<ResourceParams name="jdbc/EmployeeAppDb">
<parameter><name>username<
<parameter><name>password<
<parameter><name>driverCla
<value>org.hsql.jdbcDriver
<parameter><name>url</name
<value>jdbc:HypersonicSQL:
</ResourceParams>
<Resource name="mail/Session" auth="Container"
type="javax.mail.Session"/
<ResourceParams name="mail/Session">
<parameter>
<name>mail.smtp.host</name
<value>localhost</value>
</parameter>
</ResourceParams>
<ResourceLink name="linkToGlobalResource
global="simpleValue"
type="java.lang.Integer"/>
</Context>
</Host>
</Engine>
</Service>
<!-- The MOD_WEBAPP connector is used to connect Apache 1.3 with Tomcat 4.0
as its servlet container. Please read the README.txt file coming with
the WebApp Module distribution on how to build it.
(Or check out the "jakarta-tomcat-connectors
To configure the Apache side, you must ensure that you have the
"ServerName" and "Port" directives defined in "httpd.conf". Then,
lines like these to the bottom of your "httpd.conf" file:
LoadModule webapp_module libexec/mod_webapp.so
WebAppConnection warpConnection warp localhost:8008
WebAppDeploy examples warpConnection /examples/
The next time you restart Apache (after restarting Tomcat, if needed)
the connection will be established, and all applications you make
visible via "WebAppDeploy" directives can be accessed through Apache.
-->
<!-- Define an Apache-Connector Service -->
<!--
<Service name="Tomcat-Apache">
<Connector className="org.apache.cata
port="8008" minProcessors="5" maxProcessors="75"
enableLookups="true" appBase="webapps"
acceptCount="10" debug="0"/>
<Engine className="org.apache.cata
name="Apache" debug="0">
<Logger className="org.apache.cata
prefix="apache_log." suffix=".txt"
timestamp="true"/>
<Realm className="org.apache.cata
</Engine>
</Service>
-->
</Server>
ok that actually was the problem. I moved the prototype definition to the MyApp directory and it worked.. i should have got that one on my own.. oh well.. New problem.. Now i get this error
SQL ERROR
java.sql.SQLException: Cannot create JDBC driver of class 'COM.ibm.db2.jdbc.app.DB2D
Did you remember to set the DB2 environment for the
user tomcat is running under?
To check this try a
db2 connect to bookstr user techno using gabbo
before starting tomcat. If this works, the JDBC-driver
most likely doesn't like slackware. Workaround:
Become the DB2 instance owner. Do a db2jstrt 4777 (or
any other unused port).
Modify your server.xml to use the 'net' driver, which
doesn't contain any native code.
Following parameters in the resource definition should
be changed:
driverClassName: COM.ibm.db2.jdbc.net.DB2Dr
url: jdbc:db2://localhost:4777/
I haven't seen this before.
If you copied the db2java.zip from sqllib/java12:
Become the instance owner.
Kill the db2jd -- it needs a SIGKILL to terminate.
Do a
. sqllib/java12/usejdbc2
This makes the db2jd use the db2java.zip in sqllib/java12.
Restart the db2jd: db2jstrt 4777
Become the Tomcat user and restart Tomcat.
For details see:
http://www-3.ibm.com/cgi-b
Business Accounts
Answer for Membership
by: pjedmondPosted on 2003-01-16 at 11:59:09ID: 7743396
OK - some real quick and dirty stuff. The process that you will go through for accessing the database is:
/techinfo/ jdbc_drive r_types.ht ml
om/product s/jdbc/dri vers
ing to open DataBase"); t:3000/boo ks:user=?? ?;password =passwd"; taSource"; wInstance( ); the instantDB JDBC driver."); n(dbURL); d and connected to database TimingTest"); se opened"); t(); T *FROM students");
me")+"<BR> "); ed inserting Data"); se closed");
ion thrown");
1. Create an instance of the DB driver. Be aware that there are loads of drivers out there of different types. Go here for an understanding of the driver types:
http://www.cariboulake.com
You can get an appropriate DB2 driver from here:
http://industry.java.sun.c
2. Create a connection to the database concerned.
3. Using the connection, create a query to be run on the database.
4. Execute the query returning a result set.
Note that the structure of steps 1 and 2 will depend on the particular driver being used. Look at the documentation for the JDBC driver you eventually use.
However, to give you an idea of how it should go, I have put together a little code to give you an idea of the process, tweaked from one of my Poitbase connection scripts.
try
{
System.out.println("Prepar
//****LOCAL CONNECTION****
String dbURL="jdbc:db2://localhos
String dbDriver = "com.ibm.db2.jcc.DB2BaseDa
//************************
System.out.println("dbURL is : "+dbURL);
Class.forName(dbDriver).ne
System.out.println("Loaded
Connection conn = DriverManager.getConnectio
System.out.println("Create
System.out.println("Databa
Statement lsStmt=conn.createStatemen
ResultSet rs = lsStmt.executeQuery("SELEC
while(rs.next()){
System.out.println("First name is:"+rs.getString("firstna
}
System.out.println("Finish
conn.close();
System.out.println("DataBa
}
catch (Throwable e)
{
System.out.println("except
e.printStackTrace();
}
Hope that helps - As I've typed this in directly, I make the disclaimer that I may have made the odd systax error before I get flamed!