List of usage examples for java.sql Connection isClosed
boolean isClosed() throws SQLException;
Connection
object has been closed. From source file:com.viettel.logistic.wms.service.StockTransServiceImpl.java
private void rollback(Session session, Transaction transaction, Connection con) { try {//w w w . ja va2s. co m if (con != null) { con.rollback(); } if (transaction != null) { transaction.rollback(); } if (con != null && !con.isClosed()) { con.close(); } } catch (SQLException ex) { Logger.getLogger(StockImportServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } if (session != null && session.isOpen()) { session.close(); } }
From source file:com.dominion.salud.pedicom.web.controller.PDFController.java
/** * Genera un pdf de un pedido concreto/* ww w. j av a 2 s .c o m*/ * * @param pedidos Pedido del que se quiere generar el pdf * @return Ruta del pdf */ @ResponseBody @RequestMapping(value = "pdfPedidos", method = RequestMethod.POST, produces = "application/json") public ResponseEntity<String> pdfPedidos(@RequestBody(required = true) Pedidos pedidos) { logger.debug("Iniciando generacion del pdf"); Connection con = null; try { List<Pedidos> peds = new ArrayList<>(); peds.add(pedidos); con = routingDataSource.getConnection(); InputStream inputstream = pdfService.crearPDF(peds, con); // File dir = new File(System.getProperty("pedicom.home")); File dir = new File(PEDICOMConstantes._HOME); String nombre = Long.toString(new Date().getTime()); logger.debug(" Guardando pdf en : " + dir + "/reports/"); File tempFile = new File(dir + "/reports/", nombre + "tmp.pdf"); FileOutputStream out = new FileOutputStream(tempFile); IOUtils.copy(inputstream, out); logger.debug("Path completo :" + tempFile.getPath()); return new ResponseEntity(FilenameUtils.getName(tempFile.getPath()), HttpStatus.OK); } catch (IOException | SQLException | ClassNotFoundException | JRException ex) { logger.error(ex.getMessage()); } finally { try { if (con != null && !con.isClosed()) { con.close(); } } catch (SQLException ex) { logger.error("Error :" + ex.getMessage()); } } return new ResponseEntity("No_encontrado.pdf", HttpStatus.OK); }
From source file:EnrollFingerprint.Enroll.java
public void testOracle() { Connection conn = null; try {// w w w. j a v a2 s . c o m //DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); Class.forName("oracle.jdbc.OracleDriver"); conn = DriverManager.getConnection(connectionString); if (conn != null) { System.out.println("Conexion con Oracle exitosa!."); } else { System.out.println("Error conectandoce a Oracle Local"); } } catch (ClassNotFoundException ex) { ex.printStackTrace(); } catch (SQLException ex) { ex.printStackTrace(); } finally { try { if (conn != null && !conn.isClosed()) { conn.close(); } } catch (SQLException ex) { ex.printStackTrace(); } } }
From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManager.java
/** * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#modifyUserLock(java.lang.String, boolean, int) *//*from ww w . j a va2 s. c o m*/ public synchronized boolean modifyUserLock(final String userId, final boolean isLocked, final int increment) throws UserManagementException { final String methodName = SQLUserManager.CNAME + "#modifyUserLock(final String userId, final boolean int, final boolean increment) throws UserManagementException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", userId); DEBUGGER.debug("Value: {}", isLocked); DEBUGGER.debug("Value: {}", increment); } Connection sqlConn = null; CallableStatement stmt = null; try { sqlConn = SQLUserManager.dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); if (isLocked) { stmt = sqlConn.prepareCall("{ CALL lockUserAccount(?) }"); stmt.setString(1, userId); } else { stmt = sqlConn.prepareCall("{ CALL incrementLockCount(?) }"); stmt.setString(1, userId); } if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } return (stmt.executeUpdate() == 0); } catch (SQLException sqx) { throw new UserManagementException(sqx.getMessage(), sqx); } finally { try { if (stmt != null) { stmt.close(); } if (!(sqlConn == null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } catch (SQLException sqx) { throw new UserManagementException(sqx.getMessage(), sqx); } } }
From source file:com.cnd.greencube.server.dao.jdbc.JdbcDAO.java
@SuppressWarnings("rawtypes") public void save(Object obj, String[] columns) throws Exception { // ???// w w w . j av a 2 s.c o m Class clazz = obj.getClass(); String tableName = getTableName(clazz); if (StringUtils.isEmpty(tableName)) throw new SQLException("No @Table annotation in Class " + clazz.getName()); List<Column2Property> setterColumnsNames = getColumnsFromObj(obj, columns); if (null == setterColumnsNames || setterColumnsNames.size() == 0) throw new SQLException("Column is nul, you must specified update columns."); StringBuffer sb = new StringBuffer("insert into " + tableName); sb.append(" ( "); int size = setterColumnsNames.size(); Column2Property c; for (int i = 0; i < size; i++) { c = setterColumnsNames.get(i); if (i == 0) sb.append(c.columnName); else sb.append("," + c.columnName); } sb.append(" ) values ( "); for (int i = 0; i < size; i++) { c = setterColumnsNames.get(i); if (i == 0) sb.append("?"); else sb.append(",?"); } sb.append(" ) "); Connection conn = null; try { conn = getJdbcTemplate().getDataSource().getConnection(); TableMetaManager tableManager = TableMetaManager.getInstance(); Table t = tableManager.getTable(tableName); if (t == null) { _loadTable_(conn, tableName, clazz); t = tableManager.getTable(tableName); } if (conn.isClosed()) { throw new SQLException("Connection is closed!"); } PreparedStatement st = conn.prepareStatement(sb.toString()); for (int i = 1; i <= size; i++) { Column2Property column = setterColumnsNames.get(i - 1); if (obj == null) { st.setNull(i, java.sql.Types.NULL); continue; } Object value = MethodUtils.invokeMethod(obj, column.getterMethodName, null); if (value == null) { st.setNull(i, java.sql.Types.NULL); continue; } setColumnValue(st, column, t.getMeta(column.columnName), value, i); } st.execute(); } finally { try { conn.close(); } catch (Exception e) { } } }
From source file:org.unbunt.ella.engine.EllaCPSEngine.java
public void finish() { logger.debug("Finishing"); Set<Connection> connections = getObjConnMgr().getConnections(); for (Connection connection : connections) { try {/*from w w w . j a va2 s . c om*/ if (connection.isClosed()) { continue; } connection.close(); } catch (SQLException e) { logger.warn("Closing connection failed:", e); } } }
From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManager.java
/** * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#removeUserAccount(java.lang.String) *///from w ww . j av a2 s . co m public synchronized boolean removeUserAccount(final String userId) throws UserManagementException { final String methodName = SQLUserManager.CNAME + "#removeUserAccount(final String userId) throws UserManagementException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("userId: {}", userId); } Connection sqlConn = null; boolean isComplete = false; CallableStatement stmt = null; try { sqlConn = SQLUserManager.dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); stmt = sqlConn.prepareCall("{ CALL removeUserAccount(?) }"); stmt.setString(1, userId); if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } if (!(stmt.execute())) { isComplete = true; } } catch (SQLException sqx) { throw new UserManagementException(sqx.getMessage(), sqx); } finally { try { if (stmt != null) { stmt.close(); } if (!(sqlConn == null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } catch (SQLException sqx) { throw new UserManagementException(sqx.getMessage(), sqx); } } return isComplete; }
From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManager.java
/** * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#modifyUserPassword(java.lang.String, java.lang.String) */// w w w . j a v a2s .c o m public synchronized boolean modifyUserPassword(final String userId, final String newPass) throws UserManagementException { final String methodName = SQLUserManager.CNAME + "#modifyUserPassword(final String userId, final String newPass) throws UserManagementException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("userId: {}", userId); } Connection sqlConn = null; boolean isComplete = false; CallableStatement stmt = null; try { sqlConn = SQLUserManager.dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); // first make sure the existing password is proper // then make sure the new password doesnt match the existing password stmt = sqlConn.prepareCall("{ CALL updateUserPassword(?, ?) }"); stmt.setString(1, userId); stmt.setString(3, newPass); if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } if (stmt.executeUpdate() == 1) { isComplete = true; } } catch (SQLException sqx) { throw new UserManagementException(sqx.getMessage(), sqx); } finally { try { if (stmt != null) { stmt.close(); } if (!(sqlConn == null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } catch (SQLException sqx) { throw new UserManagementException(sqx.getMessage(), sqx); } } return isComplete; }
From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManager.java
/** * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#modifyUserEmail(java.lang.String, java.lang.String) *///from w ww. ja v a 2s . c o m public synchronized boolean modifyUserEmail(final String userId, final String value) throws UserManagementException { final String methodName = SQLUserManager.CNAME + "#modifyUserEmail(final String userId, final String value) throws UserManagementException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", userId); DEBUGGER.debug("Value: {}", value); } Connection sqlConn = null; boolean isComplete = false; CallableStatement stmt = null; try { sqlConn = SQLUserManager.dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); // first make sure the existing password is proper // then make sure the new password doesnt match the existing password stmt = sqlConn.prepareCall("{ CALL updateUserEmail(?, ?) }"); stmt.setString(1, userId); stmt.setString(2, value); if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } if (stmt.executeUpdate() == 1) { isComplete = true; } } catch (SQLException sqx) { throw new UserManagementException(sqx.getMessage(), sqx); } finally { try { if (stmt != null) { stmt.close(); } if (!(sqlConn == null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } catch (SQLException sqx) { throw new UserManagementException(sqx.getMessage(), sqx); } } return isComplete; }
From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManager.java
/** * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#modifyUserGroups(java.lang.String, java.lang.Object[]) *//* w w w. jav a 2 s . c o m*/ public synchronized boolean modifyUserGroups(final String userId, final Object[] values) throws UserManagementException { final String methodName = SQLUserManager.CNAME + "#modifyUserGroups(final String userId, final Object[] values) throws UserManagementException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", userId); DEBUGGER.debug("Value: {}", values); } Connection sqlConn = null; boolean isComplete = false; CallableStatement stmt = null; try { sqlConn = SQLUserManager.dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); // first make sure the existing password is proper // then make sure the new password doesnt match the existing password stmt = sqlConn.prepareCall("{ CALL updateUserGroups(?, ?,}"); stmt.setString(1, userId); stmt.setString(2, Arrays.toString(values)); if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } if (stmt.executeUpdate() == 1) { isComplete = true; } } catch (SQLException sqx) { throw new UserManagementException(sqx.getMessage(), sqx); } finally { try { if (stmt != null) { stmt.close(); } if (!(sqlConn == null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } catch (SQLException sqx) { throw new UserManagementException(sqx.getMessage(), sqx); } } return isComplete; }