java jdbc 同时操作查询删除操作

Connection conn = null;
        try {
            // 创建连接实例
            conn = JdbcUtility.GetFactory().CreateConn();
            conn.setAutoCommit(false);
            conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);

StringBuilder _strB = new StringBuilder();
            _strB.append(" select id from table_1 ");

Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
            ResultSet rset = stmt.executeQuery(_strB.toString());

rset.last();
            int rowCount = rset.getRow(); //获得ResultSet的总行数
            int iCount = 1;
            rset.beforeFirst();
            while (rset.next()) {
                strConcat = strConcat + rset.getString("id");
                if (rowCount != iCount) {
                    strConcat = strConcat + ",";
                }
                iCount++;
            }
            if (!strConcat.equals("")) {
                PreparedStatement pdDelete = conn.prepareStatement(" delete from "
                        +  " table_1 "
                        + " where id in (" + strConcat + ")");
                pdDelete.execute();
                pdDelete.close();
            }
            conn.commit();
            rset.close();
            stmt.close();

} catch (Exception ex) {
            if (null != conn) {
                try {
                    conn.rollback();
                } catch (SQLException se) {
                    log.error(se);
                }
            }
            log.error(ex);
        } finally {
            if (null != conn) {
                try {
                    conn.close();
                } catch (SQLException se) {
                    log.error(se);
                }
            }
        }

上一篇:Matlab中plot函数参数解析


下一篇:Linux 安装Nginx(使用Mac远程访问)