Java.sql.SQLException: Io exception: socket timeout compared to closed connection

I am trying to study this problem with the following two errors related to Oracle DB:

  • Closed connection
  • java.sql.SQLException : Io exception: socket timeout

My understanding:

  • Closed connection: either because some kind of network failure occurred, or the database closed the session due to some kind of "inactivity"
  • java.sql.SQLException : exception Io: socket timeout: this is the case when the connection was successful, but for some reason the socket / data was empty and was eventually disconnected because the data was not available.

Is it possible to replicate the above errors in a local Oracle DB database? What are the steps?

I appreciate you taking the time to respond.

Thanks.

+6
source share
2 answers

Your understanding of a closed connection is correct. Reason for a closed connection: External devices such as a firewall, network devices, and remote database users can cause network connections to close after a period of inactivity

ReadTimeOut will happen even with active connections. If the request or procedure takes a long time, you will get a read timeout exception.

  • Closed connection: shutting down the database listener when starting the database
  • ReadTimedOut: add sleep mode to the procedure for more than 10 minutes and call this procedure from the application

Replication of Socket Read Timeout Error in Oracle DB env:

  • setNetworkTimeout for SQL connection // e.g. sake, set timeout to 120 seconds
  • A database procedure call from java and sleep in this procedure for time is longer than setNetworkTimeout

     dbms_lock.sleep(125); -- sleeps for 125 seconds 

Since the procedure does not return from 120 seconds due to hibernation for 125 seconds, java will call the socket timeout in the above scenario.

+1
source

I just started working with the java.sql package. * but that’s what I understand. A closed connection is an error, and the database session is closed, but error processing is not performed, so this is the end. With java.SQException, you can control this error (use the throws clause) and print it out or execute other error handling methods.

Here is a link from Oracle on exceptions and how to handle them.

Hope this helps.

Exceptions in Java.

0
source

Source: https://habr.com/ru/post/945521/


All Articles