日期:2014-05-16  浏览次数:20465 次

批量插入数据
package importDate;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class Test2 {
    public static void main(String[] args) {
        String url = "jdbc:oracle:thin:@10.71.181.25:1521:omsdb";
        String username = "system";
        String password = "i2000db";
        Connection con = null;
        PreparedStatement ps = null;

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            con = DriverManager.getConnection(url, username, password);
            con.setAutoCommit(false);
            String sql =
                "insert into OMSFM.HISTORICAL_ALARM201012 (ALARMSN, COUNTER, CLEARED, CLEARUSER, ACKED, ACKUSER, ACKTIME, LATESTLOGTIME, LATESTLOGSN, CLEAREDTIME, CLEAREDTYPE, CLEAREDCLASS, SEVERITYCHANGEDTIME, MODN, NEDN, SOURCE, OBJECTINSTANCE, OBJECTCLASS, NETYPE, MOVERSION, NEVERSION, DEVCSN, NOTIFICATIONID, EVENTTIME, ARRIVEDTIME, EVENTTYPE, ALARMID, ALARMNAME, PERCEIVEDSEVERITY, PROBABLECAUSE, DETAILEDINFORMATION, PROPOSEDREPAIRACTIONS, BACKEDUPSTATUS, SERVICEAFFECTINGINDICATOR, ROOTCASEALARMINDICATOR, THRESHOLDINFO, ROOTCASEALARMSN, ADDITIONALTEXT, ADDITIONALINFORMATION, USERDATA) values ("
                        + "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "
                        + "?, ?, ?, ?, ?, ?, ?, ?, ?, ?"
                        + ", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?"
                        + ", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

            ps = con.prepareStatement(sql);
            for (int i = 1; i < 500001; i++) {
                ps.setInt(1, i);
                ps.setInt(2, 2);
                ps.setInt(3, 1);
                ps.setString(4, "admin");
                ps.setInt(5, 1);
                ps.setString(6, "admin");

                ps.setLong(7, 1298600949000L);
                ps.setLong(8, 1293617411000L);
                ps.setInt(9, 4);
                ps.setLong(10, 1298600960000L);
    &