java - Is there a reliable (proper?) way for code to know if a SQLException was due to a connection error? -
i know exception due connection error has string "connection closed" or similar, that's not way know if connection problem cause sql error instead of data integrity issue.
for example, if code executing multiple statements , connection dies between statement 1 , 2? how cna know know it's connection issue , not problem sttement?
example:
try { conn.createstatement().execute( sql ); //imagine dies here conn.createstatement().execute( sql2 ); } catch (sqlexception e) { //something 1 of these if ( e.geterrorcode() === sqlexception.connection_error ) {} if ( e instance of sqlcoonnectionexception ) {} }
i think looking explained here https://docs.oracle.com/javase/tutorial/jdbc/basics/sqlexception.html
oracle has given example how can retrieve lot of information error code, sqlstate etc. sqlexception.
Comments
Post a Comment