JSP Example of DB2 connection page?

Posted on 2005-05-09
Last Modified: 2013-12-10
Anyone have a JSP page with a DB2 connection in it?
I am using Websphere 5.0 and have created a datasource in the Admin Console.
Thanks in advance for your time.
Question by:g118481
    LVL 7

    Accepted Solution

    <%@ page import="java.sql.*,javax.sql.*,javax.naming.*"%>
    Context c = new InitialContext();
    DataSource ds = (DataSource)c.lookup("yourdatasourceJNDIname"); //usually something like "jdbc/myds"
    Connection conn = ds.getConnection("user","password"); // or ds.getConnection() will use default user id if you specified it
    Statement s = conn.createStatement();
    ResultSet rs = s.executeQuery("select * from table1");
         out.println("column1" + rs.getString(1) + "<br>");
    LVL 16

    Expert Comment


    You can look at the thread here. It explains how to do it. Though it is in Tomcat, it should be similar :).

    LVL 16

    Assisted Solution


    Or this IBM RedBook is good :).


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    This exercise is about for the following scenario: Dmgr and One node with 2 application server. Each application server contains it owns application. Application server name as follows server1 contains app1 server2 contains app1 Prereq…
    Upgrading Tomcat – There are a couple of methods to upgrade Tomcat is to use The Apache Installer is to download and unzip and run the services.bat remove|install Tomcat6 Because of the App that we are working with, we can only use Tomcat 6.…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now