// Takes and image_id, pulls in the image from cache, and goes about // encoding it to put it into the database in a transaction. The last // query in the transaction records the image having been stored. protected void storeImage(int image_id) throws Exception { PhotoImage p = new PhotoImage(image_id); SpyDB pdb = getDB(); Connection db = null; Statement st = null; Vector v = p.getImage(); System.err.println( "Storer: Got image for " + image_id + " " + v.size() + " lines of data to store."); try { int i = 0, n = 0; db = pdb.getConn(); db.setAutoCommit(false); st = db.createStatement(); BASE64Encoder base64 = new BASE64Encoder(); String data = ""; for (; i < v.size(); i++) { String tmp = base64.encodeBuffer((byte[]) v.elementAt(i)); tmp = tmp.trim(); if (data.length() < 2048) { data += tmp + "\n"; } else { storeQuery(image_id, n, st, data); data = tmp; n++; } } // OK, this is sick, but another one right now for the spare. if (data.length() > 0) { System.err.println("Storer: Storing spare."); storeQuery(image_id, n, st, data); n++; } System.err.println("Storer: Stored " + n + " lines of data for " + image_id + "."); st.executeUpdate( "update upload_log set stored=datetime(now())\n" + "\twhere photo_id = " + image_id); db.commit(); // Go ahead and generate a thumbnail. p.getThumbnail(); } catch (Exception e) { // If anything happens, roll it back. if (st != null) { try { db.rollback(); } catch (Exception e3) { // Nothing } } } finally { if (db != null) { try { db.setAutoCommit(true); } catch (Exception e) { System.err.println("Error: " + e); } } pdb.freeDBConn(); } }
public final void rollback() { try { m_conn.rollback(); } catch (SQLException e) { throw new IllegalStateException(e); } }
/** * Sets the user to run as. This is for the case where the request was generated by the user and * so the worker must set this value later. * * @param cq_id id of this entry in the queue * @param user user to run the jobs as */ public void setRunAs(long cq_id, String user) throws MetaException { try { Connection dbConn = getDbConn(); try { Statement stmt = dbConn.createStatement(); String s = "update COMPACTION_QUEUE set cq_run_as = '" + user + "' where cq_id = " + cq_id; LOG.debug("Going to execute update <" + s + ">"); if (stmt.executeUpdate(s) != 1) { LOG.error("Unable to update compaction record"); LOG.debug("Going to rollback"); dbConn.rollback(); } LOG.debug("Going to commit"); dbConn.commit(); } catch (SQLException e) { LOG.error("Unable to update compaction queue, " + e.getMessage()); try { LOG.debug("Going to rollback"); dbConn.rollback(); } catch (SQLException e1) { } detectDeadlock(e, "setRunAs"); } finally { closeDbConn(dbConn); } } catch (DeadlockException e) { setRunAs(cq_id, user); } finally { deadlockCnt = 0; } }
/** * Control de transacción desde el cliente * * @param prod */ @Override public void create1(Producto prod) { Connection cn = null; try { // Variables Statement stm; PreparedStatement pstm; String query; int id; ResultSet rs; // Conexión cn = AccesoDB.getConnection(); // Iniciar la Tx cn.setAutoCommit(false); // Obtener el Id del producto query = "select sq_producto.NextVal id from dual"; stm = cn.createStatement(); rs = stm.executeQuery(query); rs.next(); id = rs.getInt("id"); // Insertar el producto query = "insert into producto" + "(idprod,idcat,nombre,precio,stock) " + "values(?,?,?,?,?) "; pstm = cn.prepareStatement(query); pstm.setInt(1, id); pstm.setInt(2, prod.getIdcat()); pstm.setString(3, prod.getNombre()); pstm.setDouble(4, prod.getPrecio()); pstm.setInt(5, prod.getStock()); pstm.executeUpdate(); // Retornar el id prod.setIdprod(id); // Confirmar Tx cn.commit(); // Cerrar objetos rs.close(); stm.close(); pstm.close(); } catch (SQLException e) { try { cn.rollback(); } catch (Exception e1) { } throw new RuntimeException(e.getMessage()); } catch (Exception e) { try { cn.rollback(); } catch (Exception e1) { } throw new RuntimeException("Error en el proceso crear producto."); } finally { try { cn.close(); } catch (Exception e) { } } }
@Override public void delete(int id) { Connection cn = null; String query; PreparedStatement pstm; ResultSet rs; int cont; try { cn = AccesoDB.getConnection(); cn.setAutoCommit(false); // Verificar si el producto rgistra ventas query = "select count(*) cont from detalle where idprod = ?"; pstm = cn.prepareStatement(query); pstm.setInt(1, id); rs = pstm.executeQuery(); rs.next(); cont = rs.getInt("cont"); rs.close(); pstm.close(); if (cont > 0) { throw new SQLException("El producto registra ventas, no se puede eliminar."); } // Eliminar el producto query = "delete from producto where idprod=?"; pstm = cn.prepareStatement(query); pstm.setInt(1, id); int filas = pstm.executeUpdate(); if (filas == 0) { throw new SQLException( "Código de producto no existe, " + "posiblemente fue eliminado por otro usuario."); } cn.commit(); pstm.close(); } catch (SQLException e) { try { cn.rollback(); } catch (Exception e1) { } throw new RuntimeException(e.getMessage()); } catch (Exception e) { try { cn.rollback(); } catch (Exception e1) { } throw new RuntimeException("Error al tratar de eliminar el producto."); } finally { try { cn.close(); } catch (Exception e) { } } }
/** * Find entries in the queue that are ready to be cleaned. * * @return information on the entry in the queue. */ public List<CompactionInfo> findReadyToClean() throws MetaException { Connection dbConn = getDbConn(); List<CompactionInfo> rc = new ArrayList<CompactionInfo>(); try { Statement stmt = dbConn.createStatement(); String s = "select cq_id, cq_database, cq_table, cq_partition, " + "cq_type, cq_run_as from COMPACTION_QUEUE where cq_state = '" + READY_FOR_CLEANING + "'"; LOG.debug("Going to execute query <" + s + ">"); ResultSet rs = stmt.executeQuery(s); while (rs.next()) { CompactionInfo info = new CompactionInfo(); info.id = rs.getLong(1); info.dbname = rs.getString(2); info.tableName = rs.getString(3); info.partName = rs.getString(4); switch (rs.getString(5).charAt(0)) { case MAJOR_TYPE: info.type = CompactionType.MAJOR; break; case MINOR_TYPE: info.type = CompactionType.MINOR; break; default: throw new MetaException("Unexpected compaction type " + rs.getString(5)); } info.runAs = rs.getString(6); rc.add(info); } LOG.debug("Going to rollback"); dbConn.rollback(); return rc; } catch (SQLException e) { LOG.error("Unable to select next element for cleaning, " + e.getMessage()); try { LOG.debug("Going to rollback"); dbConn.rollback(); } catch (SQLException e1) { } throw new MetaException( "Unable to connect to transaction database " + StringUtils.stringifyException(e)); } finally { closeDbConn(dbConn); } }
public void insertBumper(String bumper) throws Exception { Connection conn = null; PreparedStatement prep = null; try { conn = getConnection(); conn.setAutoCommit(false); prep = conn.prepareStatement("insert or ignore into bumper" + " values(null,?,?,?,?,?);"); prep.setString(1, bumper); prep.setBoolean(2, false); prep.setString(3, Util.formatDate(new Date())); prep.setString(4, Util.formatDate(new Date())); prep.addBatch(); prep.executeBatch(); conn.commit(); } catch (Exception e) { LotteryLogger.getInstance().setError("error in saving bumper ," + e.getMessage()); if (conn != null) conn.rollback(); throw new Exception("error in saving bumper"); } finally { if (prep != null) prep.close(); if (conn != null) conn.close(); } }
/* * Updates a purchaseItem tuple. * Returns true if the update is successful; false otherwise. * * All arguments cannot be null. */ public boolean updatePurchaseItem(int receiptID, int upc, int quantity) { try { ps = con.prepareStatement( "UPDATE purchaseitem SET quantity = ? WHERE receiptID = ? AND upc = ?"); ps.setInt(1, quantity); ps.setInt(2, receiptID); ps.setInt(3, upc); ps.executeUpdate(); if (commit) con.commit(); return true; } catch (SQLException ex) { ExceptionEvent event = new ExceptionEvent(this, ex.getMessage()); fireExceptionGenerated(event); try { con.rollback(); return false; } catch (SQLException ex2) { event = new ExceptionEvent(this, ex2.getMessage()); fireExceptionGenerated(event); return false; } } }
/* * Insert a PurchaseItem Returns true if the insert is successful; false * otherwise. */ public boolean insertPurchaseItem(Integer pirid, Integer piupc, Integer piquantity) { try { ps = con.prepareStatement("INSERT INTO purchaseitem VALUES (?,?,?)"); ps.setInt(1, pirid.intValue()); ps.setInt(2, piupc.intValue()); ps.setInt(3, piquantity.intValue()); ps.executeUpdate(); if (commit) con.commit(); return true; } catch (SQLException ex) { ExceptionEvent event = new ExceptionEvent(this, ex.getMessage()); fireExceptionGenerated(event); try { con.rollback(); return false; } catch (SQLException ex2) { event = new ExceptionEvent(this, ex2.getMessage()); fireExceptionGenerated(event); return false; } } }
/* * Deletes a PurchaseItem tuple. Returns true if the delete is successful; false * otherwise. */ public boolean deletePurchaseItem(Integer rid, Integer upc) { try { ps = con.prepareStatement("DELETE FROM purchaseitem WHERE receiptid = ? AND upc = ?"); ps.setInt(1, rid.intValue()); ps.setInt(2, upc.intValue()); ps.executeUpdate(); if (commit) con.commit(); return true; } catch (SQLException ex) { ExceptionEvent event = new ExceptionEvent(this, ex.getMessage()); fireExceptionGenerated(event); try { con.rollback(); return false; } catch (SQLException ex2) { event = new ExceptionEvent(this, ex2.getMessage()); fireExceptionGenerated(event); return false; } } }
/** * Used for looking up information in DB * * @param Query string * @param what the user is searching for * @return The result of the query in a ResultSet * @throws SQLException - if you screwed up the query. Jerk. */ public ResultSet sql(String statement, SQLType type) throws SQLException { try { Statement stmt = con.createStatement(); ResultSet rs; if (type == SQLType.query) { rs = stmt.executeQuery(statement); return rs; } else if (type == SQLType.insert) { stmt.executeUpdate(statement); } else if (type == SQLType.delete) { stmt.execute(statement); } return null; } catch (SQLException ex) { System.out.println("Message: " + ex.getMessage()); try { // undo the insert con.rollback(); } catch (SQLException ex2) { System.out.println("Message: " + ex2.getMessage()); throw ex2; } throw ex; } }
public static void format(String kq_date) throws Exception { Connection con = null; try { con = com.gemway.igo.JDatabase.getPkJDatabase().getConnection(); con.setAutoCommit(false); for (JCompany comObj : JCompany.getFlCompanyList()) { java.util.List<Branch> lsBranch = com.gemway.igo.fl.Branch.getBranches(comObj.getCompany_id()); for (int i = 0; lsBranch != null && i < lsBranch.size(); i++) { format(con, kq_date, lsBranch.get(i).getBranch_id()); } } con.commit(); } catch (Throwable e) { JLog.getLogger().error("自动生成日度考勤服务出错:", e); } finally { if (con != null) { try { con.rollback(); con.close(); con = null; } catch (Exception e) { } } } }
// // Examine BLOBs and CLOBs. // private void vetLargeObjects( Connection conn, HashSet<String> unsupportedList, HashSet<String> notUnderstoodList) throws Exception { Statement stmt = conn.createStatement(); stmt.execute("CREATE TABLE t (id INT PRIMARY KEY, " + "b BLOB(10), c CLOB(10))"); stmt.execute( "INSERT INTO t (id, b, c) VALUES (1, " + "CAST (" + TestUtil.stringToHexLiteral("101010001101") + "AS BLOB(10)), CAST ('hello' AS CLOB(10)))"); ResultSet rs = stmt.executeQuery("SELECT id, b, c FROM t"); rs.next(); Blob blob = rs.getBlob(2); Clob clob = rs.getClob(3); vetObject(blob, unsupportedList, notUnderstoodList); vetObject(clob, unsupportedList, notUnderstoodList); stmt.close(); conn.rollback(); }
/* * Manager sets the delivered date for an order. * Returns true if the change has been successfully made, returns false otherwise. */ public boolean setDeliveredDate(int receiptID, Date deliveredDate) { try { ps = con.prepareStatement( "UPDATE Purchase " + "SET deliveredDate = ? " + "WHERE receiptID = ?"); ps.setDate(1, deliveredDate); ps.setInt(2, receiptID); ps.executeUpdate(); con.commit(); return true; } catch (SQLException ex) { ExceptionEvent event = new ExceptionEvent(this, ex.getMessage()); fireExceptionGenerated(event); try { con.rollback(); return false; } catch (SQLException ex2) { event = new ExceptionEvent(this, ex2.getMessage()); fireExceptionGenerated(event); return false; } } }
public void addOrder(ShoppingCart cart, String userName, Order order) throws SQLException { Connection c = null; PreparedStatement ps = null; Statement s = null; ResultSet rs = null; boolean transactionState = false; try { s = c.createStatement(); transactionState = c.getAutoCommit(); int userKey = getUserKey(userName, c, ps, rs); c.setAutoCommit(false); addSingleOrder(order, c, ps, userKey); int orderKey = getOrderKey(s, rs); addLineItems(cart, c, orderKey); c.commit(); order.setOrderKeyFrom(orderKey); } catch (SQLException sqlx) { s = c.createStatement(); c.rollback(); throw sqlx; } finally { try { c.setAutoCommit(transactionState); dbPool.release(c); if (s != null) s.close(); if (ps != null) ps.close(); if (rs != null) rs.close(); } catch (SQLException ignored) { } } }
private void rollbackCommit() { try { conn.rollback(); } catch (SQLException e) { printSQLException(e); } }
public void rollback(Savepoint savepoint) { try { con.rollback(savepoint); } catch (Exception ex) { ex.printStackTrace(); } }
public static void exexuteUpdate2(String sql[], String[][] parameters) { try { ct = getConnection(); ct.setAutoCommit(false); for (int i = 0; i < parameters.length; i++) { if (parameters[i] != null) { ps = ct.prepareStatement(sql[i]); for (int j = 0; j < parameters[i].length; j++) { ps.setString(j + 1, parameters[i][j]); } ps.executeUpdate(); } } ct.commit(); } catch (Exception e) { e.printStackTrace(); try { ct.rollback(); } catch (SQLException e1) { e1.printStackTrace(); } throw new RuntimeException(e.getMessage()); } finally { close(rs, ps, ct); } }
@Override public void delete(Integer deptno) { int updateCount_EMPs = 0; Connection con = null; PreparedStatement pstmt = null; try { Class.forName(driver); con = DriverManager.getConnection(url, userid, passwd); // 1●設定於 pstm.executeUpdate()之前 con.setAutoCommit(false); // 先刪除員工 pstmt = con.prepareStatement(DELETE_EMPs); pstmt.setInt(1, deptno); updateCount_EMPs = pstmt.executeUpdate(); // 再刪除部門 pstmt = con.prepareStatement(DELETE_DEPT); pstmt.setInt(1, deptno); pstmt.executeUpdate(); // 2●設定於 pstm.executeUpdate()之後 con.commit(); con.setAutoCommit(true); System.out.println("刪除部門編號" + deptno + "時,共有員工" + updateCount_EMPs + "人同時被刪除"); // Handle any driver errors } catch (ClassNotFoundException e) { throw new RuntimeException("Couldn't load database driver. " + e.getMessage()); // Handle any SQL errors } catch (SQLException se) { if (con != null) { try { // 3●設定於當有exception發生時之catch區塊內 con.rollback(); } catch (SQLException excep) { throw new RuntimeException("rollback error occured. " + excep.getMessage()); } } throw new RuntimeException("A database error occured. " + se.getMessage()); } finally { if (pstmt != null) { try { pstmt.close(); } catch (SQLException se) { se.printStackTrace(System.err); } } if (con != null) { try { con.close(); } catch (Exception e) { e.printStackTrace(System.err); } } } }
@Override public void update(Producto prod) { Connection cn = null; try { // Variables PreparedStatement pstm; String query; int filas; // Conexión cn = AccesoDB.getConnection(); // Iniciar la Tx cn.setAutoCommit(false); // Insertar el producto query = "update producto set idcat=?, nombre=?, precio=?, " + "stock=? where idprod = ? "; pstm = cn.prepareStatement(query); pstm.setInt(1, prod.getIdcat()); pstm.setString(2, prod.getNombre()); pstm.setDouble(3, prod.getPrecio()); pstm.setInt(4, prod.getStock()); pstm.setInt(5, prod.getIdprod()); filas = pstm.executeUpdate(); if (filas == 0) { throw new SQLException("Producto no existe."); } // Confirmar Tx cn.commit(); // Cerrar objetos pstm.close(); } catch (SQLException e) { try { cn.rollback(); } catch (Exception e1) { } throw new RuntimeException(e.getMessage()); } catch (Exception e) { try { cn.rollback(); } catch (Exception e1) { } throw new RuntimeException("Error en el proceso crear producto."); } finally { try { cn.close(); } catch (Exception e) { } } }
public void insertCustomers(List<Customer> customers) throws Exception { Connection conn = null; PreparedStatement prep = null; try { init(); conn = getConnection(); conn.setAutoCommit(false); for (Customer customer : customers) { prep = conn.prepareStatement( "insert into customer values ( null," + "?," + "?," + "?," + " ?," + "?," + " ?," + "?," + "? ," + "? ," + "?," + "?," + "?," + "? , ?, ?);"); prep.setInt(1, customer.getSerialNumber()); prep.setString(2, customer.getSeries()); prep.setString(3, customer.getTicketNumber()); prep.setString(4, customer.getName()); prep.setString(5, customer.getLotteryType()); prep.setString(6, customer.getBumperName()); prep.setString(7, customer.getPhoneNumber()); prep.setString(8, customer.getEmailId()); prep.setString(9, customer.getAddress()); prep.setBoolean(10, false); prep.setBoolean(11, false); prep.setString(12, Constants.backupMessage); prep.setString(13, Util.formatDate(customer.getDate())); prep.setString(14, Util.formatDate(new Date())); prep.setString(15, Util.formatDate(new Date())); prep.addBatch(); prep.executeBatch(); prep.close(); } conn.commit(); } catch (Exception e) { LotteryLogger.getInstance().setError("Error in inserting customers," + e.getMessage()); if (conn != null) conn.rollback(); throw new Exception("Error in inserting customer," + e.getMessage()); } finally { if (prep != null) prep.close(); if (conn != null) conn.close(); } }
public static void ConnecttoOracle(String username, String password) { // Declare a null Connection: Connection c = null; try { // try begin: System.out.println(" ******************************** "); System.out.println(" CREATION OF TABLES FOR LAB REVIEW 5 "); System.out.println(" ******************************** "); System.out.println("* Loading the driver *"); // declare the connection: // Set driver name: Class.forName("oracle.jdbc.driver.OracleDriver"); // home url: String url = "jdbc:oracle:thin:@localhost:1521:XM"; // school url: // String url = "jdbc:oracle:thin:@ E10818:1521:orcl"; c = DriverManager.getConnection(url, username, password); // what is means of this line, i need to ask:##__##__1 c.setAutoCommit(true); // declare a stactement s from Connection c: Statement s = c.createStatement(); System.out.println("****** Creating Faculty table ******"); String query = "CREATE TABLE faculty"; query = query + "(f_id number (5), f_last VARCHAR2 (30), f_first VARCHAR2 (30), " + "CONSTRAINT faculty_f_id_pk PRIMARY KEY (f_id))"; // execute query: s.executeUpdate(query); System.out.println("****** inserting into Faculty table ******"); System.out.println("****** 1 - Roberton - Myra ******"); System.out.println(" ******** 1 - Robertson - Myra ********"); query = "INSERT INTO faculty "; query = query + "(f_id, f_last, f_first ) "; query = query + "values"; query = query + "(1, 'Robertson', 'Myra') "; s.executeUpdate(query); c.commit(); c.setAutoCommit(true); c.close(); } // try end. catch (Exception e) { try { c.rollback(); } catch (Exception ee) { System.out.println("Error !"); } System.out.println("Error - Database Management for creating tables () : " + e); } }
protected void rollback() throws DataStoreException { try { mConnection.rollback(); } catch (SQLException e) { throw new DataStoreException(e); } }
public static boolean rollback(final Connection connection) { try { connection.rollback(); return true; } catch (Exception e) { return false; } }
/** * Elimina al registro a través de la entidad dada por vData. * * <p><b> delete from GRLRegistroPNC where iEjercicio = ? AND iConsecutivoPNC = ? </b> * * <p><b> Campos Llave: iEjercicio,iConsecutivoPNC, </b> * * @param vData TVDinRep - VO Dinámico que contiene a la entidad a Insertar. * @param cnNested Connection - Conexión anidada que permite que el método se encuentre dentro de * una transacción mayor. * @throws DAOException - Excepción de tipo DAO * @return boolean - En caso de ser o no eliminado el registro. */ public boolean delete(TVDinRep vData, Connection cnNested) throws DAOException { DbConnection dbConn = null; Connection conn = cnNested; PreparedStatement lPStmt = null; boolean lSuccess = true; String cMsg = ""; try { if (cnNested == null) { dbConn = new DbConnection(dataSourceName); conn = dbConn.getConnection(); conn.setAutoCommit(false); conn.setTransactionIsolation(2); } // Ajustar Where de acuerdo a requerimientos... String lSQL = "delete from GRLRegistroPNC where iEjercicio = ? AND iConsecutivoPNC = ? "; // ... lPStmt = conn.prepareStatement(lSQL); lPStmt.setInt(1, vData.getInt("iEjercicio")); lPStmt.setInt(2, vData.getInt("iConsecutivoPNC")); lPStmt.executeUpdate(); if (cnNested == null) { conn.commit(); } } catch (SQLException sqle) { lSuccess = false; cMsg = "" + sqle.getErrorCode(); } catch (Exception ex) { warn("delete", ex); if (cnNested == null) { try { conn.rollback(); } catch (Exception e) { fatal("delete.rollback", e); } } lSuccess = false; } finally { try { if (lPStmt != null) { lPStmt.close(); } if (cnNested == null) { if (conn != null) { conn.close(); } dbConn.closeConnection(); } } catch (Exception ex2) { warn("delete.close", ex2); } if (lSuccess == false) throw new DAOException(cMsg); return lSuccess; } }
public void excluirLote(List<JobLote> listaExcluir) { Connection conn = null; PreparedStatement stmt = null; String sql = "delete from joblote where job = ? and operacao = ? and lote =? "; try { conn = GerenciaConexaoSQLServer.abreConexao(); conn.setAutoCommit(false); for (int i = 0; i <= listaExcluir.size() - 1; i++) { JobLote job = listaExcluir.get(i); stmt = conn.prepareStatement(sql); stmt.setString(1, job.getJob().trim().replace(".", "")); stmt.setInt(2, job.getOperNum()); stmt.setInt(3, job.getLote()); stmt.executeUpdate(); alteraJobAposExclusao(conn, job); gravaJobsExcluidos( conn, job.getJob().trim().replace(".", ""), job.getOperNum(), job.getLote()); } // adiciona a op na tela inicial for (int i = 0; i <= listaExcluir.size() - 1; i++) { JobLote job = listaExcluir.get(i); JobProtheus jobProtheus = retornaJob(conn, job); adicionaOPTelaInicial(conn, jobProtheus, job); } JOptionPane.showMessageDialog(this, "Job Excluido com Sucesso!"); conn.commit(); } catch (SQLException e) { if (conn != null) { try { conn.rollback(); conn.setAutoCommit(true); JOptionPane.showMessageDialog(null, "Não foi possivel excluir! Descrição: " + e); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "Erro ao fazer o rollback! Descrição: " + ex); } } } finally { GerenciaConexaoSQLServer.closeConexao(conn, stmt); } }
/** * Rollbacks a connection. * * @param con Connection to be rollbacked. */ public void rollback(Connection con) { if (con != null) { try { con.rollback(); } catch (SQLException ex) { LOG.error("Cannot rollback transaction", ex); } } }
public int createRelease(String label, String releaseDesc) { Connection dbConn = null; PreparedStatement prepStmt = null; Statement stmt = null; ResultSet rset = null; try { dbConn = ds.getConnection(); dbConn.setAutoCommit(false); stmt = dbConn.createStatement(); rset = stmt.executeQuery("select nextval('release_id_seq')"); rset.next(); int ret = rset.getInt(1); rset.close(); prepStmt = dbConn.prepareStatement("insert into release values(?, ?, now(), ?)"); prepStmt.setInt(1, ret); prepStmt.setString(2, label); if (releaseDesc == null) { prepStmt.setNull(3, Types.VARCHAR); } else { prepStmt.setString(3, releaseDesc); } prepStmt.execute(); dbConn.commit(); return ret; } catch (SQLException e) { try { dbConn.rollback(); } catch (Exception ee) { } throw new RuntimeException(e); } finally { try { rset.close(); } catch (Exception e) { } try { stmt.close(); } catch (Exception e) { } try { prepStmt.close(); } catch (Exception e) { } try { dbConn.close(); } catch (Exception e) { } } }
public synchronized void close() { for (Connection conn : allConnections) { try { conn.rollback(); } catch (SQLException ex) { throw new RuntimeException(ex); } } allConnections.clear(); }
public static String saveTopologyData(Customer cust, TopologyData3 td) { String text = null; try { boolean needRollback = true; Connection c = ManagementContainer.getInstance().getDBConnection(ManagementContainer.POOL_NAME); try { TopologyStats ts = saveTopologyData(cust, td, c); if (td.getRunType() != DirectoryData.TYPE_MANUAL_NOCOMMIT) { c.commit(); needRollback = false; } switch (td.getRunType()) { case DirectoryData.TYPE_MANUAL_FORCED: text = s_topologySuccessMessageForced.format( new Object[] { ts.getAdminGroupCount(), ts.getRoutingGroupCount(), ts.getServerCount(), ts.getStoreCount() }); break; case DirectoryData.TYPE_MANUAL_NOCOMMIT: text = s_topologySuccessMessageNoCommit.format( new Object[] { ts.getAdminGroupCount(), ts.getRoutingGroupCount(), ts.getServerCount(), ts.getStoreCount() }); break; default: text = s_topologySuccessMessage.format( new Object[] { ts.getAdminGroupCount(), ts.getRoutingGroupCount(), ts.getServerCount(), ts.getStoreCount() }); } return text; } finally { if (needRollback) { c.rollback(); } ManagementContainer.getInstance().safeReturnDBConnection(c, ManagementContainer.POOL_NAME); // report info **after** connection is closed if (s_logger.isDebugEnabled()) { s_logger.debug("saveTopologyData completed: " + text); } } } catch (Exception e) { s_logger.error("Exception while saving the topology data.", e); return "An error occurred while saving the topology data."; } }