Commit 06ad2fba authored by Ajit Deshmukh's avatar Ajit Deshmukh

Closed the open connections.

parent 491e6f9a
...@@ -2302,12 +2302,15 @@ ...@@ -2302,12 +2302,15 @@
BaseLogger.log("3", null, null, "executeAndLog inputSql: [" + inputSql + "]"); BaseLogger.log("3", null, null, "executeAndLog inputSql: [" + inputSql + "]");
BaseLogger.log("3", null, null, "executeAndLog execRights: [" + execRights + "]"); BaseLogger.log("3", null, null, "executeAndLog execRights: [" + execRights + "]");
BaseLogger.log("3", null, null, "executeAndLog schemaName: [" + schemaName + "]"); BaseLogger.log("3", null, null, "executeAndLog schemaName: [" + schemaName + "]");
try {
try { try {
conn = connDriver1.getConnectDB("Driver"); conn = connDriver1.getConnectDB("Driver");
} catch (Exception e) { } catch (Exception e) {
System.out.println("Catch block for connection failed...." + e.getMessage()); System.out.println("Catch block for connection failed...." + e.getMessage());
String error = e.getMessage(); String error = e.getMessage();
logSqlExecution(tranId, enterpriseCode, "0", requestID, inputSql, 0, "E", userId, chgTerm, error, ""); logSqlExecution(tranId, enterpriseCode, "0", requestID, inputSql, 0, "E", userId, chgTerm, error,
"");
return; // Stop execution if connection fails return; // Stop execution if connection fails
} }
// Changes by Ajit D. on 08-JUNE-26 for the query execution schema name fetched // Changes by Ajit D. on 08-JUNE-26 for the query execution schema name fetched
...@@ -2356,16 +2359,18 @@ ...@@ -2356,16 +2359,18 @@
} else { } else {
try{ try {
connForSchema = connDriverForSchema.getConnectDB(schemaName); connForSchema = connDriverForSchema.getConnectDB(schemaName);
}catch (Exception e) { } catch (Exception e) {
String error = (e.getMessage() != null) String error = (e.getMessage() != null)
? e.getMessage() ? e.getMessage()
: e.toString(); : e.toString();
System.out.println("Catch block for executeAndLog method for creating connection 1...." + error); System.out
logSqlExecution(tranId, enterpriseCode, "0", requestID, inputSql, 0, "E", userId, chgTerm, error, ""); .println("Catch block for executeAndLog method for creating connection 1...." + error);
logSqlExecution(tranId, enterpriseCode, "0", requestID, inputSql, 0, "E", userId, chgTerm,
error, "");
return;
} }
System.out.println( System.out.println(
...@@ -2391,6 +2396,8 @@ ...@@ -2391,6 +2396,8 @@
null, null,
"Actual Oracle USER : [" "Actual Oracle USER : ["
+ schemaForPlaceHolder + "]"); + schemaForPlaceHolder + "]");
schemaForRs.close();
schemaForPs.close();
} }
if (schemaName.equalsIgnoreCase("APPVIS") || schemaName.equalsIgnoreCase("APPVISQC")) { if (schemaName.equalsIgnoreCase("APPVIS") || schemaName.equalsIgnoreCase("APPVISQC")) {
...@@ -2430,20 +2437,22 @@ ...@@ -2430,20 +2437,22 @@
System.out.println("execSchema:: " + execSchema); System.out.println("execSchema:: " + execSchema);
System.out.println("enterpriseCode:: " + enterpriseCode); System.out.println("enterpriseCode:: " + enterpriseCode);
// Comment out this part as for creating connection for Live schema does not
//Comment out this part as for creating connection for Live schema does not need to use schema_name value instead use db_main value directly[26-June-2026] // need to use schema_name value instead use db_main value
// directly[26-June-2026]
// 1. Get the Connection String for the Main Execution // 1. Get the Connection String for the Main Execution
/* /*
String connForExecSql = "select schema_name from enterprise where enterprise = ?"; * String connForExecSql =
PreparedStatement connForExecPstmt = conn.prepareStatement(connForExecSql); * "select schema_name from enterprise where enterprise = ?";
connForExecPstmt.setString(1, enterpriseCode); * PreparedStatement connForExecPstmt = conn.prepareStatement(connForExecSql);
ResultSet connForExecRs = connForExecPstmt.executeQuery(); * connForExecPstmt.setString(1, enterpriseCode);
while (connForExecRs.next()) { * ResultSet connForExecRs = connForExecPstmt.executeQuery();
System.out.println( * while (connForExecRs.next()) {
"EXECUTION CONNECTION USER ::: " * System.out.println(
+ connForExecRs.getString(1)); * "EXECUTION CONNECTION USER ::: "
connForExec = connForExecRs.getString("schema_name"); * + connForExecRs.getString(1));
} * connForExec = connForExecRs.getString("schema_name");
* }
*/ */
connForExec = schemaName; connForExec = schemaName;
...@@ -2464,11 +2473,11 @@ ...@@ -2464,11 +2473,11 @@
? e.getMessage() ? e.getMessage()
: e.toString(); : e.toString();
System.out.println("Catch block for executeAndLog method for creating connection...." + error); System.out.println("Catch block for executeAndLog method for creating connection...." + error);
logSqlExecution(tranId, enterpriseCode, "0", requestID, inputSql, 0, "E", userId, chgTerm, error, ""); logSqlExecution(tranId, enterpriseCode, "0", requestID, inputSql, 0, "E", userId, chgTerm, error,
"");
} }
int updCount = 0; int updCount = 0;
String error = null; String error = null;
...@@ -2544,13 +2553,15 @@ ...@@ -2544,13 +2553,15 @@
String dropSynSql = "DROP SYNONYM " + dbRead + "." + objName; String dropSynSql = "DROP SYNONYM " + dbRead + "." + objName;
System.out.println( System.out.println(
"Attempting to drop related synonym via Enterprise Config: " + dropSynSql); "Attempting to drop related synonym via Enterprise Config: "
+ dropSynSql);
// Execute blindly. If it doesn't exist, we catch the exception. // Execute blindly. If it doesn't exist, we catch the exception.
stmt.execute(dropSynSql); stmt.execute(dropSynSql);
System.out.println("Synonym dropped successfully."); System.out.println("Synonym dropped successfully.");
} else { } else {
System.out.println("Skipping synonym drop: DB_READ not found in Enterprise table."); System.out.println(
"Skipping synonym drop: DB_READ not found in Enterprise table.");
} }
} }
} catch (SQLException synEx) { } catch (SQLException synEx) {
...@@ -2629,6 +2640,31 @@ ...@@ -2629,6 +2640,31 @@
if (conn != null) if (conn != null)
conn.close(); conn.close();
} }
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (connForSchema != null && !connForSchema.isClosed()) {
connForSchema.close();
connForSchema = null;
}
if (connForQueryExec != null && !connForQueryExec.isClosed()) {
connForQueryExec.close();
connForQueryExec = null;
}
if (conn != null && !conn.isClosed()) {
conn.close();
conn = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}
} }
private boolean isDdl(String sql) { private boolean isDdl(String sql) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment