The transaction management ORACLE

Because of work requirements, you need to insert the ORACLE data large amounts of data, and then select the open transaction manual management, a lot of data insertion, but this ran into a pit, before the insertion of data through open mysql transaction management, copy mysql the method is a bit does not work, only 299 data can be inserted into each insertion, I started to think that the code in question, careful examination revealed no problem with the code, find out the reasons from the internet, use the following methods can be opened in JDBC ORACLE transaction management, batch insert data. Pro-test available:

// insert data into tissue *** 
    public  void insertZZ (the JSONArray JA) throws SQLException {
         // connected intermediate library 
        String User = " **** " ; 
        String password = " ***** " ; 
        String URL = " JDBC : Oracle: Thin: @ip: Port / the SID " ; 
        String Driver = " oracle.jdbc.driver.OracleDriver " ; 
        connection CON = null ; // a long connection object database package TCP connection length
 //         the Statement stmt = null ; //And a package managing SQL statements java object 

        the PreparedStatement the preparedStatement = null ; 

        // insert data 
        the try { 
            the Class.forName (Driver); 
            CON = the DriverManager.getConnection (URL, User, password); 

            // transaction commit the transaction mode is set to manual :
 //             con.setAutoCommit (false);
             // set the transaction isolation level.
//             con.setTransactionIsolation (Connection.TRANSACTION_REPEATABLE_READ); 

            // Run insert 
            int J = 2 ; 
            String SQL = "INSERT INTO IUFO_UNIT_INFO(DR,LEVEL_CODE,TS,UNIT_CODE,UNIT_ID,UNIT_NAME,UNIT_TYPE) \n" +
                    "values(?,?,?,?,?,?,?)";
            preparedStatement = con.prepareStatement(sql);
            for (int i = 0; i < ja.size(); i++) {
                JSONObject jo = ja.getJSONObject(i);
                String dr = (String) jo.get("dr");
                String level_code = (String) jo.get("level_code");
                String ts = (String) jo.get("ts");
                String unit_code = (String) jo.get("code");
                String unit_id = (String) jo.get("unit_id");
                String unit_name = (String) jo.get("name");
                String unit_type = (String) jo.get("unit_type");

//                String sql = "INSERT INTO IUFO_UNIT_INFO(DR,LEVEL_CODE,TS,UNIT_CODE,UNIT_ID,UNIT_NAME,UNIT_TYPE) \n" +
//                        "values('"+dr+"','"+level_code+"','"+ts+"','"+unit_code+"','"+unit_id+"','"+unit_name+"','"+unit_type+"')";

                preparedStatement.setString(1,dr);
                preparedStatement.setString(2,level_code);
                preparedStatement.setString(3,ts);
                preparedStatement.setString(4,unit_code);
                preparedStatement.setString(5,unit_id);
                preparedStatement.setString(6, UNIT_NAME); 
                PreparedStatement.setString ( . 7 , UNIT_TYPE); 
                PreparedStatement.addBatch (); 

//                 int PreparedStatement.executeUpdate the resultSet = ();
 //                 System.out.println (J); 

            } 
            PreparedStatement.executeBatch (); 

            // commit the transaction 
            con.commit (); 


        } the catch (exception E) {
             // if unusual transaction occurs, roll back the transaction 
            con.rollback (); 
        } the finally { 
      // open transaction automatically submit con.setAutoCommit (
to true ); the try { if (preparedStatement != null) { preparedStatement.close(); } if (con != null) { con.close(); } } catch (SQLException e) { e.printStackTrace(); } } }

 

Guess you like

Origin www.cnblogs.com/gxlaqj/p/11240346.html