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

  • Home
  • SEARCH
  • 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 8682477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:47:10+00:00 2026-06-12T21:47:10+00:00

Just to ensure that I am correctly creating and closing database connection, I wrote

  • 0

Just to ensure that I am correctly creating and closing database connection, I wrote the following code. This is a simple java code with nothing but core java, Oracle thin client, connecting to Oracle 10g XE instance. I had expected this code to run without any problem – since it was just creating and closing connection (in a single thread) – many times over. But the problem is after running for a few times (20ish) it throws error.

The code:

public class TestConnection {
private final static Logger logger = LoggerFactory
        .getLogger(TestConnection.class);

@Rule
public ContiPerfRule i = new ContiPerfRule();

@Test
@PerfTest(invocations = 100, threads = 1)
@Required(max = 1200, average = 1000)
public void test() {

    Connection connection = null;
    try {
        // Load the JDBC driver
        String driverName = "oracle.jdbc.driver.OracleDriver";
        Class.forName(driverName);

        // Create a connection to the database
        String serverName = "127.0.0.1";
        String portNumber = "1521";
        String sid = "XE";
        String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber
                + ":" + sid;
        String username = "funngames";
        String password = "funngames";
        connection = DriverManager.getConnection(url, username, password);
        assertNotNull(connection);
        logger.debug("Connection made.");

    } catch (ClassNotFoundException e) {
        logger.debug(e.getMessage());
    } catch (SQLException e) {
        logger.debug(e.getMessage());
    } finally {
        if (connection != null) {
            try {
                connection.close();
                logger.debug("Connection broken.");
            } catch (SQLException e) {
                logger.debug(e.getMessage());
                fail("The connection could not be closed.");
            }
        }
    }
}

}

And the error it throws is

ORA-12519, TNS:no appropriate service handler found

Important to note, if I run this just once – not 100 times as shown in the code snippet above – it works absolutely fine. If I run it 100 times, it runs for a few time (20 – 25 times) and then exits with the error shown above. For example the snippet shows that many connections were open and were successfully closed, but immediately after that it starts throwing error.

    foo.bar.database.TestConnection.test
16:39:17.854 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:17.854 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:17.869 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:17.869 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:17.885 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:17.885 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:17.901 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:17.901 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:17.916 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:17.916 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:17.932 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:17.932 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:17.948 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:17.948 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:17.979 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:17.979 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:17.994 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:17.994 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:18.010 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:18.010 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:18.026 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:18.026 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:18.041 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:18.041 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:18.057 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:18.057 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:18.073 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:18.073 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:18.088 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:18.088 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:18.104 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:18.104 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:18.119 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:18.119 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:18.135 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:18.135 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:18.151 [main] DEBUG foo.bar.database.TestConnection - Connection made.
16:39:18.151 [main] DEBUG foo.bar.database.TestConnection - Connection broken.
16:39:18.166 [main] DEBUG foo.bar.database.TestConnection - Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
The Connection descriptor used by the client was:
127.0.0.1:1521:XE

Any ideas, what is wrong with this scenario?

If you wanted more context on what exactly I am trying to do, I have blogged about it here.

  • 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-12T21:47:12+00:00Added an answer on June 12, 2026 at 9:47 pm

    Ok. Found out the issue.

    Hypothesis – The connection closing bit is happening at two levels 1. the java code 2. the database server. In my code the java bit is closing connection quicker than the database server is able to close them (expected because it is really the database server which is doing most of the job there). Hence there is a bit of race condition, where the java code is assuming that previous connection is closed and is trying to create a new one, while the database server has not been able to close the previous connection yet.

    Proof – if I make java code wait a bit after it has managed to close connection, then this code works fine. I had this modified piece of java code execute in a loop 1000 times over and it ran alright. Compare this with the fact that when I reported this issue, the code will only run about 20 – 25 times before tripping over.

    The new code (just the modification) …

    ...
    finally {
    if (connection != null) {
        try {
            connection.close();
            logger.debug("Connection broken.");
            Thread.sleep(1000);
        } catch (SQLException e) {
            logger.debug(e.getMessage());
            e.printStackTrace();
            fail("The connection could not be closed.");
        } catch (InterruptedException e) {
            logger.debug(e.getMessage());
            e.printStackTrace();
    
        }
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just to be on the safe side, what's the best practice to ensure that
Just learning the world of jquery, and all my googling gives examples like this:
just wondering if there is a way to reduce the amount of code needed
Just see this: SELECT clientid,clientname,startdate,enddate,age FROM clients WHERE clientid IN (1,2,3,4,5) AND CASE WHEN
I have a simple web form that sends and email out via .NET C#.
I'm implementing in-app billing support in my application. I just realized that even though
I've managed to boil this down to the following test case but I'm wondering
This one is really confusing me. I'm dispatching an IndexChangedEvent that I've created myself,
How can I ensure that my custom field's *to_python()* method is only called when
How can I ensure that my custom field's *to_python()* method is only called when

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.