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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:19:21+00:00 2026-06-03T02:19:21+00:00

I’m using JDBC Connection pooling with mysql. This is my code private static DataSource

  • 0

I’m using JDBC Connection pooling with mysql.
This is my code

    private static DataSource   _ds;

    /**
    * create the data source if it doesn't exist
    */
private DataSource getDataSource() throws FileNotFoundException,
        IOException, URISyntaxException
{
    if (_ds != null)
        return _ds;


    PoolProperties p = new PoolProperties();
    p.setUrl(url);
    p.setDriverClassName(driver);
    p.setUsername(username);
    p.setTestOnBorrow(true);
    if (password != null)
    {
        p.setPassword(password);
    }
    p.setValidationQuery(validationQuery);
    p.setJdbcInterceptors(JDBC_INTERCEPTOR);
    DataSource datasource = new DataSource();
    datasource.setPoolProperties(p);
    _ds = datasource;
    return datasource;
}

/**
 * gets a connection from the JDBC pool
 * 
 * @throws SQLException
 * @throws IOException
 * @throws FileNotFoundException
 * @throws URISyntaxException 
 */
public Connection getConnection() throws SQLException,
        FileNotFoundException, IOException, URISyntaxException
{
    Connection con = getDataSource().getConnection();
    con.setAutoCommit(false);
    return con;
}

And whenever i want to use a connection I do :

con = getInstance().getConnection();
stmt = con.createStatement();
resultSet = stmt.executeQuery(selectQuery);

The problem is that the results of the query are not realtime. That is if I change something in the DB and commit, the query in java doesn’t get the changes.same happens if the DB is changed from another app

Note : the changes are taken after a while, or if i restart tomcat

Is there anything wrong with my code? anyway to fix this error?

Thank you

  • 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-03T02:19:22+00:00Added an answer on June 3, 2026 at 2:19 am

    Most probably this is caused by MySQL’s default isolation level which is REPEATABLE READ.

    This means that you don’t see changes done by other transactions until you end (commit, rollback) your “own” transaction (remember: a SELECT already starts a transaction)

    As the connections in a pool are never closed, those transactions are probably not ended. Try issuing a commit or rollback before running the select.

    For a permanent solution you can either change the default isolation by configuring your connection pool (most of them allow this), change the transaction level by calling setTransactionIsolation() on the connection or by changing the default level in MySQL.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the

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.