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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:59:03+00:00 2026-05-27T18:59:03+00:00

I have a datasource set in my Jetty.xml file that looks like this: <New

  • 0

I have a datasource set in my Jetty.xml file that looks like this:

<New id="MySQL_DS" class="org.eclipse.jetty.plus.jndi.Resource">
  <Arg></Arg>
  <Arg>jdbc/MySQL_DS</Arg>
  <Arg>
    <New class="com.mchange.v2.c3p0.ComboPooledDataSource">
      <Set name="driverClass">com.mysql.jdbc.Driver</Set>
      <Set name="jdbcUrl">jdbc:mysql:[IP]</Set>
      <Set name="user">[USER]</Set>
      <Set name="password">[PASSWORD]</Set>
      <Set name="checkoutTimeout">5000</Set>
      <Set name="initialPoolSize">3</Set>
      <Set name="maxIdleTime">3600</Set>
      <Set name="maxPoolSize">50</Set>
      <Set name="minPoolSize">1</Set>
      <Set name="maxStatements">200</Set>
      <Set name="maxConnectionAge">0</Set>
      <Set name="acquireIncrement">3</Set>
    </New>
  </Arg>
</New>

It is defined in my web.xml like so:

<resource-ref>
  <description>DB Connection</description>
  <res-ref-name>jdbc/MySQL_DS</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>

And I bind to my datasource like this in my servlet code:

InitialContext ctx = new InitialContext();
_dataSource = (DataSource)ctx.lookup("java:comp/env/jdbc/MySQL_DS");

My question is:

I need to have 4 servlet using this context lookup, on the same datasource. Is such a thing even possible?

I mean, can multiple servlets bind to the same datasource, or must each servlet have their own one?

I’m asking this because I have one servlet that is working correctly but another one throws a javax.naming.NameNotFoundException (remaining name jdbc/MySQL_DS).

Thanks!

  • 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-27T18:59:04+00:00Added an answer on May 27, 2026 at 6:59 pm

    As far as I know, you shouldn’t have to specify unique data sources for each servlet.

    I’m working on a Java EE web application that has multiple servlets in it that all use one data source for connecting to the DB. This web application uses Oracle as the back-end and WebLogic Server as the application server.

    In this web application’s architecture, there’s a dedicated class for connecting to the DB. All of the servlets invoke this class to get a connection to the DB.

    This connection class has the following lines in the constructor (similar to yours above)…

    InitialContext ic=new InitialContext();
    DataSource ds=(DataSource) ic.lookup("jdbc/OracleDS");
    con=ds.getConnection("user","pwd"); \\ ("con" is a private Connection instance var)

    Then, each of the servlets just use the connection class to connect into the DB.

    For instance…

    MyConnectionClass con = new MyConnectionClass(); // ("MyConnectionClass" is where the data source info is...)
    PreparedStatement ps=con.prepareStatement("SELECT * FROM SOME_TABLE");
    ResultSet rs=ps.executeQuery();
    more code below...

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

Sidebar

Related Questions

If I have a control on a page that has its Datasource set to
I have a BindingList<> of a class set to the DataSource property of a
I have a DataGridView with the DataSource set to List<myClass> However, the new row
I have a class that works like so: @Component public class MyClass { @Autowired
I have a Devexpress.XtraGrid.GridControl that I have set the DataSource to a DataTable .
I run jboss in standalone mode and have set my datasource in the standalone.xml
I have a DGV that has its datasource set to a BindingList. There is
I have a DataGridView with its datasource set to a generic list of custom
I have a ComboBox with its DataSource set to an instance of a DataTable.
I have DataGridView and I set DataSource of datagridview by using DataTables. DataTable dt

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.