Advertisement

01.16.2003 at 10:28AM PST, ID: 20460211
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Tomcat - Using DB2 and JDBC

Tags: db2, tomcat, jdbc
Ok 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.
Start your free trial to view this solution
Question Stats
Zone: Software
Question Asked By: touquet
Solution Provided By: mglxxx
Participating Experts: 2
Solution Grade: A
Views: 93
Translate:
Loading Advertisement...
01.16.2003 at 11:59AM PST, ID: 7743396

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.16.2003 at 12:00PM PST, ID: 7743404

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.20.2003 at 10:22AM PST, ID: 7762380

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.22.2003 at 03:19PM PST, ID: 7786718

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.22.2003 at 11:57PM PST, ID: 7789610

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.23.2003 at 11:20AM PST, ID: 7794073

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.23.2003 at 11:28AM PST, ID: 7794131

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.25.2003 at 07:30AM PST, ID: 7808419

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.26.2003 at 10:52PM PST, ID: 7819187

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.27.2003 at 02:31AM PST, ID: 7820102

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.27.2003 at 02:49AM PST, ID: 7820193

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.27.2003 at 02:56AM PST, ID: 7820209

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.27.2003 at 03:24AM PST, ID: 7820327

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.27.2003 at 03:27AM PST, ID: 7820346

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.27.2003 at 04:41PM PST, ID: 7826039

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.27.2003 at 11:20PM PST, ID: 7827881

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.28.2003 at 06:50PM PST, ID: 7834661

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.28.2003 at 11:07PM PST, ID: 7835670

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.29.2003 at 07:11AM PST, ID: 7838353

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.29.2003 at 07:13AM PST, ID: 7838366

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.29.2003 at 07:52AM PST, ID: 7838773

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
01.16.2003 at 11:59AM PST, ID: 7743396
OK - some real quick and dirty stuff. The process that you will go through for accessing the database is:

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/techinfo/jdbc_driver_types.html

You can get an appropriate DB2 driver from here:

http://industry.java.sun.com/products/jdbc/drivers

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("Preparing to open DataBase");
     //****LOCAL CONNECTION****
     String dbURL="jdbc:db2://localhost:3000/books:user=???;password=passwd";
        String dbDriver = "com.ibm.db2.jcc.DB2BaseDataSource";
     //************************
     System.out.println("dbURL is : "+dbURL);
        Class.forName(dbDriver).newInstance();
        System.out.println("Loaded the instantDB JDBC driver.");
        Connection conn = DriverManager.getConnection(dbURL);
        System.out.println("Created and connected to database TimingTest");
     System.out.println("Database opened");
     Statement lsStmt=conn.createStatement();
     ResultSet rs = lsStmt.executeQuery("SELECT *FROM students");
       
        while(rs.next()){
            System.out.println("First name is:"+rs.getString("firstname")+"<BR>");
         }
     System.out.println("Finished inserting Data");
     conn.close();
     System.out.println("DataBase closed");

}
catch (Throwable e)
{
          System.out.println("exception thrown");
        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!
 
01.16.2003 at 12:00PM PST, ID: 7743404
Now just insert the above into the servlet.....obviously make sure that the DB itself is running correctly first:)

Have fun:)

 
01.20.2003 at 10:22AM PST, ID: 7762380
Here's my version using DB connection pooling and JNDI
Get the following packages from
http://jakarta.apache.org/commons:
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/db2java.zip $CATALINA_HOME/common/lib/db2java.jar
Note the extension .jar in the copied file. This is important!

Now configure the datasource for tomcat. Edit $CATALINA_HOME/conf/server.xml and add the following
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.dbcp.BasicDataSourceFactory</value>
            </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</name>
              <value>COM.ibm.db2.jdbc.app.DB2Driver</value>
            </parameter>
            <parameter>
              <name>url</name>
              <value>jdbc:db2:wasrepos</value>
            </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/html");
      out.println("<html>\n<head>\n<title>DSTestServlet</title>\n</head>");
      out.println("<body style=\"background-color: white;\">");
      if ( dsName == null ) {
          out.println("<h1>Parameter 'ds' is empty.</h1>");
      } else {
          try {
            Context initCtx = new InitialContext();
            Context envCtx = (Context)initCtx.lookup("java:comp/env");

            DataSource ds = (DataSource)envCtx.lookup(dsName);
            Connection conn = ds.getConnection();
            out.println("<h1>Successfully connected to " + dsName +
                      "</h1>");
            conn.close();
            out.println("<h1>Successfully disconnected from " + dsName +
                      "</h1>");
          }
          catch (SQLException e) {
            out.println("<h1>Connect failed: " + e + "</h1>");
          }
          catch (NamingException e) {
            out.println("<h1>NamingException while resolving " + dsName +
                      ": " + e);
          }
            catch (InterruptedException e) { }
      }
      out.println("</body>\n</html>");
      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/db2profile
(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/DSTestServlet?ds=jdbc/db2ds

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.DB2Driver and the url by
jdbc:db2://localhost:4777/wasrepos. Remember to start
the DB2 java daemon on the DB server machine,. if you
are using the "net" driver: db2jstrt 4777
 
 
01.22.2003 at 03:19PM PST, ID: 7786718
/**
 * 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,HttpServletResponse response) throws ServletException,IOException
        {
                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.jdbc.app.DB2Driver");                //The DB2 driver will have to go on this line
                Connection con = DriverManager.getConnection("jdbc:odbc:PrototypeBooks",usr,passwd);    //This line will als$
                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.toString());
                }
                catch (SQLException e)
                {
                        System.out.println(e.toString());
                }
                catch (Exception e)
                {
                        System.out.println(e.toString());
                }

           }
}
 
01.22.2003 at 11:57PM PST, ID: 7789610
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.dbcp.BasicDataSourceFactory</value>
           </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</value>
           </parameter>
           <parameter>
             <name>driverClassName</name>
             <value>COM.ibm.db2.jdbc.app.DB2Driver</value>
           </parameter>
           <parameter>
             <name>url</name>
             <value>jdbc:db2:PrototypeBooks</value>
           </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,HttpServletResponse response) throws ServletException,IOException
       {
               PrintWriter out = response.getWriter();
               String FIRSTNAME,LASTNAME;
               out.println("<html>\n<head>\n<title>" +
                           "Student Names</title>" +
                           "\n</head>\n<body>");

               
               try
               {
               
          Context initCtx = new InitialContext();
          Context envCtx = (Context)initCtx.lookup("java:comp/env");

          DataSource ds = (DataSource)envCtx.lookup("jdbc/PrototypeBooks");
          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</html>");

          }
}
 
01.23.2003 at 11:20AM PST, ID: 7794073
I followed your(mqlxxx) instructions and when i ran the servlet it threw the NamingException what does this mean and how would i fix it???
 
01.23.2003 at 11:28AM PST, ID: 7794131
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.
 
01.25.2003 at 07:30AM PST, ID: 7808419
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.catalina.mbeans.ServerLifecycleListener"
            debug="0"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
            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.UserDatabase"
       description="User database that can be updated and saved">
    </Resource>
    <ResourceParams name="UserDatabase">
      <parameter>
        <name>factory</name>
        <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
      </parameter>
      <parameter>
        <name>pathname</name>
        <value>conf/tomcat-users.xml</value>
      </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.coyote.tomcat4.CoyoteConnector"
               port="80" minProcessors="5" maxProcessors="75"
               enableLookups="true" redirectPort="8443"
               acceptCount="10" debug="0" connectionTimeout="20000"
               useURIValidationHack="false" />
    <!-- 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.coyote.tomcat4.CoyoteConnector"
               port="8443" minProcessors="5" maxProcessors="75"
               enableLookups="true"
             acceptCount="10" debug="0" scheme="https" secure="true"
               useURIValidationHack="false">
      <Factory className="org.apache.coyote.tomcat4.CoyoteServerSocketFactory"
               clientAuth="false" protocol="TLS" />
    </Connector>
    -->

    <!-- Define a Coyote/JK2 AJP 1.3 Connector on port 8009 -->
    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
               port="8009" minProcessors="5" maxProcessors="75"
               enableLookups="true" redirectPort="8443"
               acceptCount="10" debug="0" connectionTimeout="20000"
               useURIValidationHack="false"
               protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"/>

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <!--
    <Connector className="org.apache.ajp.tomcat4.Ajp13Connector"
               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.coyote.tomcat4.CoyoteConnector"
               port="8082" minProcessors="5" maxProcessors="75"
               enableLookups="true"
               acceptCount="10" debug="0" connectionTimeout="20000"
               proxyPort="80" useURIValidationHack="false" />
    -->

    <!-- Define a non-SSL legacy HTTP/1.1 Test Connector on port 8083 -->
    <!--
    <Connector className="org.apache.catalina.connector.http.HttpConnector"
               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.catalina.connector.http10.HttpConnector"
               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/examples/WEB-INF/classes/filters").

           Request dumping is disabled by default.  Uncomment the following
           element to enable it. -->
      <!--
      <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
      -->

      <!-- Global logger unless overridden at lower levels -->
      <Logger className="org.apache.catalina.logger.FileLogger"
              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.catalina.realm.UserDatabaseRealm"
                 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.catalina.realm.MemoryRealm" />
      -->

      <!-- 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.catalina.realm.JDBCRealm" debug="99"
             driverName="org.gjt.mm.mysql.Driver"
          connectionURL="jdbc:mysql://localhost/authority"
         connectionName="test" connectionPassword="test"
              userTable="users" userNameCol="user_name" userCredCol="user_pass"
          userRoleTable="user_roles" roleNameCol="role_name" />
      -->

      <!--
      <Realm  className="org.apache.catalina.realm.JDBCRealm" debug="99"
             driverName="oracle.jdbc.driver.OracleDriver"
          connectionURL="jdbc:oracle:thin:@ntserver:1521:ORCL"