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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:24:03+00:00 2026-06-05T15:24:03+00:00

On a DataSource interface I found two methods to get Connection, with and without

  • 0

On a DataSource interface I found two methods to get Connection, with and without username and password paramenters.

Connection getConnection()
Connection getConnection(String username, String password)

Stated that I’d like to use a connection pool exposed as JNDI Resource from the server (tomcat) what differences are from the two methods?

  • 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-06-05T15:24:04+00:00Added an answer on June 5, 2026 at 3:24 pm

    Depending on the DataSource implementation, these two methods do different things. The first, with no arguments, simply obtains a Connection from the pool, configured with credentials configured when the DataSource was created. The second, which accepts new credentials, will obtain a Connection from the DataSource that was opened using those credentials, or it will create a new Connection with those credentials or — if the JDBC driver supports it — it will take an existing Connection and switch the credentials (I’m not sure if this is really even possible).

    Unfortunately, the JavaDoc (http://docs.oracle.com/javase/7/docs/api/javax/sql/DataSource.html) does not really give you any insight to why one might call one versus the other. The obvious reason is because you want to connect using credentials other than those configured for the entire DataSource.

    The default DataSource that Tomcat will configure for you is a BasicDataSource from the Apache commons-dbcp: this DataSource does not support the getConnection(String username, String password) method. Recent versions of Tomcat ship with tomcat-pool, which is an alternative DataSource implementation that does support this alternative mechanism (although the current documentation says it does not) if you set the alternateUsernameAllowed="true" attribute on your <Resource> element.

    Tomcat-pool documentation: http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html

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

Sidebar

Related Questions

I set the datasource for a WPF dxg:GridControl to that of a hard coded
I'm implementing a datasource object for an UIScrollView. Is that part of the Controller,
Given a datasource like that: var c = new Car[] { new Car{ Color=Blue,
Suppose an example. I have following interface: public interface DataSource<T> { Future<T> fetch(); }
I have an interface like below public interface FooDAO { public void callA(String x);
All Types implement IEnumerable interface could be used for a DataSource of a DataList.
Why DataSource interface does not define the Standard Data Source Properties specified by the
I have two objects: User and Client, both implements interface IMember interface IMember {
I am stuck with BindingList where T is an interface that extends A interface.
I have a java application that uses jtds driver and commons-dbcp as a connection

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.