public static Connection getConnection() throws ReportSQLException {
try {
- return AppUtils.getDatasource().getConnection();
+ return AppUtils.getDatasource().getConnection();
} catch(SQLException ex) {
- ex.printStackTrace();
+ ex.printStackTrace();
}
return null;
} // getConnection
public static void clearConnection(Connection con) throws ReportSQLException {
try {
- if ((con != null) && !con.isClosed())
- Globals.getDbUtils().clearConnection(con);
+ if ((con != null) && !con.isClosed()) {
+ Globals.getDbUtils().clearConnection(con);
+ }
} catch (SQLException ex) {
throw new ReportSQLException(ex.getMessage(), ex.getCause());
} catch (Exception ex2 ) {
String result = null;
try {
- if(con.isClosed()) con = getConnection();
+ if(con.isClosed()) con = getConnection();
logger.debug(EELFLoggerDelegate.debugLogger, ("[SQL CALL FROM RAPTOR] [SQL Call] " + sql));
- CallableStatement stmt = con.prepareCall(sql);
- if (expectResult)
- stmt.registerOutParameter(1, Types.CHAR);
- stmt.executeUpdate();
- if (expectResult)
- result = stmt.getString(1);
- stmt.close();
- con.commit();
+ try(CallableStatement stmt = con.prepareCall(sql)){
+ if (expectResult)
+ stmt.registerOutParameter(1, Types.CHAR);
+ stmt.executeUpdate();
+ if (expectResult)
+ result = stmt.getString(1);
+ con.commit();
+ }
} catch (SQLException e) {
throw new ReportSQLException(e.getMessage(), sql);
} finally {
} // executeCall
public static int executeUpdate(Connection con, String sql) throws ReportSQLException {
- int rcode = -1;
- try {
- Statement stmt = con.createStatement();
+ int rcode = -1;
+ try(Statement stmt = con.createStatement()) {
logger.debug(EELFLoggerDelegate.debugLogger, ("[SQL CALL FROM RAPTOR] [SQL Update] " + sql));
rcode = stmt.executeUpdate(sql);
- stmt.close();
- //con.commit();
+ //con.commit();
} catch (SQLException e) {
//e.printStackTrace();
throw new ReportSQLException(e.getMessage(), sql);
- }
- return rcode;
+ }
+ return rcode;
} // executeUpdate
-
+
public static int executeUpdate(String sql) throws ReportSQLException {
Connection con = null;
try {
public static DataSet executeQuery(Connection con, String sql, int maxRowLimit)
throws ReportSQLException {
try {
- if(con.isClosed()) con = getConnection();
+ if(con.isClosed()) con = getConnection();
//con.
- Statement stmt = con.createStatement();
-
- logger.debug(EELFLoggerDelegate.debugLogger, ("[SQL CALL FROM RAPTOR] [SQL] " + sql));
- ResultSet rs = stmt.executeQuery(sql);
- DataSet ds = new DataSet(rs, maxRowLimit);
-
- if(rs!=null)
- rs.close();
- if(stmt!=null)
- stmt.close();
-
- return ds;
+ try(Statement stmt = con.createStatement();
+ ResultSet rs = stmt.executeQuery(sql))
+ {
+ logger.debug(EELFLoggerDelegate.debugLogger, ("[SQL CALL FROM RAPTOR] [SQL] " + sql));
+ return new DataSet(rs, maxRowLimit);
+ }
} catch (SQLException e) {
throw new ReportSQLException(e.getMessage(), sql);
- }
+ }
} // executeQuery
public static DataSet executeQuery(String sql) throws ReportSQLException {