Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7420287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:12:42+00:00 2026-05-29T08:12:42+00:00

I have set up jdbc connection pooling in a java-ee environment by doing the

  • 0

I have set up jdbc connection pooling in a java-ee environment by doing the following changes.

    The context.xml 

<Context> 
        <Resource name="jdbc/mysybase" auth="Container" 
                  type="javax.sql.DataSource" driverClassName="com.sybase.jdbc3.jdbc.SybDriver" 
                  url="jdbc:sybase:Tds:H2S33.studtrack.com:2025/student" 
                  username="scott" password="tiger" maxActive="20" maxIdle="10" 
                  maxWait="-1"/> 
    </Context> 


    In The web.xml file 
    <resource-ref> 
     <description>Sybase Datasource example</description> 
     <res-ref-name>jdbc/mysybase</res-ref-name> 
     <res-type>javax.sql.DataSource</res-type> 
     <res-auth>Container</res-auth> 
    </resource-ref> 


    And the jsp page 

    <%@page import="java.sql.*"%> 
    <%@page import="javax.naming.Context"%> 
    <%@page import="javax.naming.InitialContext"%> 
    <%@page import="java.sql.Connection"%> 
    <%@page import="java.sql.SQLException"%> 
    <%@page import="java.sql.ResultSet"%> 
    <%@page import="javax.sql.DataSource"%> 
    <html> 
    <head> 
    <title>Obtaining a Connection</title> 
    </head> 
    <body> 

    <% 
        Connection conn = null; 
        ResultSet result = null; 
        Statement stmt = null; 
         try { 
           Context initContext = new InitialContext(); 
        Context envContext  = (Context)initContext.lookup("java:/comp/env"); 
           DataSource ds = (DataSource)envContext.lookup("jdbc/mysybase"); 
           conn = ds.getConnection(); 
        if (conn != null)  
        { 
            String message = "Got Connection " + conn.toString() + ", "; 
            out.write(message); 
        } 
        else 
        { 
            out.write("hello no conn obtained"); 

        } 

            stmt = conn.createStatement(); 
            result = stmt.executeQuery("SELECT * FROM Student"); 
        while(result.next()) 
        { 
            out.write(result.getString("name")); 
        } 

         } 
         catch (SQLException e) { 
             out.write("Error occurred " + e); 
          } 

    %> 

    </body> 
    </html>

Now i want the jdbc pooling to be available in normal java classes as well.
Do i need to make any changes if i want the pooling to be available in java classes.
Can i get a connection object in a java class just as i got the connection in the jsp as shown above.

Connection conn = null; 
ResultSet result = null; 
Statement stmt = null;
Context initContext = new InitialContext(); 
Context envContext  = (Context)initContext.lookup("java:/comp/env"); 
DataSource ds = (DataSource)envContext.lookup("jdbc/mysybase"); 
conn = ds.getConnection(); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:12:43+00:00Added an answer on May 29, 2026 at 8:12 am

    1.) You can set a contextListener to initialize connection only once and get logical conn from the pool (gues you use tomcat’s DBCP).

    2.) Yes, once you start a connection (driver sets a socket and the pool gets initialized) from context data, you can get a connection (from the pool) properly invoking that from any java class.

    3.) Try not to put pure Java code in JSPs. Just a rule of the road: is treated as a poor decision.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following hibernate.cfg.xml : <hibernate-configuration> <session-factory> <property name=hibernate.format_sql>true</property> <property name=hibernate.show_sql>true</property> <property name=hibernate.connection.url>jdbc:mysql://localhost/EJB</property>
I have hibernate.cfg.xml file. <session-factory> <!-- Database connection settings --> <property name=connection.driver_class>com.mysql.jdbc.Driver</property> <property name=connection.url></property>
currently i have jdbc code with the following basic stucture: get Connection (do the
On a glassfish server I have a JDBC Connection pool set up for my
I have set of scripts for doing scripted installs. You can use the scripts
I have the following code: Hashtable env1 = new Hashtable(); env1.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,com.ibm.websphere.naming.WsnInitialContextFactory); log.info(Executed step 1);
I have set up Tomcat to use a connection pool yet after the MySQL
I want to set up a connection pool and JDBC connection on EAR deployment
I have a web app on Tomcat, which handles DB connection pooling, and using
I've set the classpath envoirenment but still get an error Exception:com.mysql.jdbc.Driver Do you have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.