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 5948339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:05:37+00:00 2026-05-22T17:05:37+00:00

I am working on establishing Database connection in my GWT Application with MySQL. I

  • 0

I am working on establishing Database connection in my GWT Application with MySQL. I want the database to read a set of ‘init’ parameters so as I dont need to ‘hand code’ DB URL and Usernames and Passwords.
I googled a while for possible solutions but got a bit overwhelmed by the possible solutions. Some of them talked of JNDI as solution but none where clear as to how to do it.

Moreover the differences in running your application from Eclipse in development/debugging mode(in Jetty) and finally deploying it in Tomcat is further confusing me.

Is it possible to specify set of Init Parameters in web.xml ? How do I read them?

If JNDI is to be used? Can I get a step by step concise summary of how to achieve this task?

  • 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-22T17:05:37+00:00Added an answer on May 22, 2026 at 5:05 pm

    What you are looking for is web app context setting –

    To add the database info in web app context

    • http://wiki.metawerx.net/wiki/Context.xml
    • this file goes in your war/META-INF directory

    To configure jetty, you will have to use the jetty-web.xml configuration also –

    • http://docs.codehaus.org/display/JETTY/jetty-web.xml
    • This goes in your war/WEB-INF directory

    To do a connection in your app, on the server side use the following –

            Context ctx = new InitialContext();
    
            DataSource  ds = (DataSource) ctx.lookup("java:comp/env/{Res Name in context.xml}");
            Connection conn = ds.getConnection();
    

    NOTE –
    To have both your app run both with jetty and tomcat,have both the files and make sure your resource name is-

    context.xml : {resourceName}

    jetty-web.xml: java:comp/env/{resourceName}

    Not sure if jetty-web.xml will work with just {resourcename} too

    EDIT – sample context.xml code –

    <Resource name="jdbc/myDatabaseServer" auth="Container" type="javax.sql.DataSource"
        maxActive="100" maxIdle="30" maxWait="10000" username="USER"
        password="PWD" driverClassName="com.mysql.jdbc.Driver"
        url="jdbc:mysql://myUrl:3306/myDB?autoReconnect=true" removeAbandoned="true"
        removeAbandonedTimeout="60" logAbandoned="true" autoReconnect="true" validationQuery="select 1" testOnBorrow="true"
        testOnReturn="true" testWhileIdle="true" timeBetweenEvictionRunsMillis="1800000"
        numTestsPerEvictionRun="3" minEvictableIdleTimeMillis="1800000"/>
    

    Same sample jetty-web.xml code –

    <New id="someid" class="org.mortbay.jetty.plus.naming.Resource">
        <Arg>java:comp/env/jdbc/myDatabaseServer</Arg>
        <Arg>
            <New class="org.apache.commons.dbcp.BasicDataSource">
                <Set name="driverClassName">com.mysql.jdbc.Driver</Set>
                <Set name="url">jdbc:mysql://myUrl:3306/myDB?autoReconnect=true</Set>
                <Set name="username">USER</Set>
                <Set name="password">PWD</Set>
                <Set name="maxActive">100</Set>
                <Set name="maxIdle">30</Set>
                <Set name="minIdle">0</Set>
                <Set name="maxWait">10000</Set>
                <Set name="minEvictableIdleTimeMillis">1800000</Set>
                <Set name="timeBetweenEvictionRunsMillis">1800000</Set>
                <Set name="numTestsPerEvictionRun">3</Set>
                <Set name="testOnBorrow">true</Set>
                <Set name="testWhileIdle">true</Set>
                <Set name="testOnReturn">true</Set>
                <Set name="validationQuery">SELECT 1</Set>
            </New>
        </Arg>
    </New>
    

    You can read up on what each sections mean.

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

Sidebar

Related Questions

Working with an Oracle 9i database from an ASP.NET 2.0 (VB) application using OLEDB.
i am establishing connection with the server and its working fine. But there are
I am working on a mobile communicator and after establishing connection to the server
Working on a project where a sequential set of methods must be run every
I have apache and mysql set up on my local machine (Mac). Whenever I
Working with an API where I need to send a value over in an
I am working on establishing a Bluetooth Piconet among multiple devices in a testbed.
Working on dom html . I want to convert node value to string: $html
Working on a project an need a specific effect on the homepage. When a
I'm working on a Java application that collects various bits of information on network

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.