在JAVA程序中,有1000万个数据需要增加,想请问一下是用什么方式处理会好一些 Connection conn = null;
PreparedStatement pstmt = conn.prepareStatement( "sql1" );
pstmt.execute();增加一条是这样,很多条也这样不大行吧
PreparedStatement pstmt = conn.prepareStatement( "sql1" );
pstmt.execute();增加一条是这样,很多条也这样不大行吧
解决方案 »
- 求高手点拨“Oracle公司的中国知识产权保护渠道与办法”。
- 请教一个oracle学习的初级问题
- 菜鸟求教 sqlexd结构的介绍
- 在jdeveloper10.1.2中加载程序是提示“ error loading business components for project D:\rehouse\fwk\fwk.jpr”
- 查询各个年龄段的人数的SQL语句
- 求CNOUG论坛(oracle.com.cn)邀请码一个,非常感谢!
- 在oracle保存二进制文件的问题,在线,给分
- 江湖救急--求ORACLE SQL语句,各位请进……>
- 在oracle数据库备份时出现的一个问题:
- 如何实现两个表之间的___级联更新
- oracle关联操作的一个奇怪问题,解决者马上给分
- 多表关联查询,如何只取其中一条记录?
e265. Executing a Batch of SQL Statements in a Database
With batch updating, a set of SQL statements is assembled and then sent altogether to the database for execution. Batch updating can improve performance.This example creates a batch of insert statements. Auto-commit is disabled so that you have the choice of committing or not in the event of an exception. try {
// Disable auto-commit
connection.setAutoCommit(false);
// Create a prepared statement
String sql = "INSERT INTO my_table VALUES(?)";
PreparedStatement pstmt = connection.prepareStatement(sql);
// Insert 10 rows of data
for (int i=0; i<10; i++) {
pstmt.setString(1, ""+i);
pstmt.addBatch();
}
// Execute the batch
int [] updateCounts = pstmt.executeBatch();
// All statements were successfully executed.
// updateCounts contains one element for each batched statement.
// updateCounts[i] contains the number of rows affected by that statement.
processUpdateCounts(updateCounts);
// Since there were no errors, commit
connection.commit();
} catch (BatchUpdateException e) {
// Not all of the statements were successfully executed
int[] updateCounts = e.getUpdateCounts();
// Some databases will continue to execute after one fails.
// If so, updateCounts.length will equal the number of batched statements.
// If not, updateCounts.length will equal the number of successfully executed statements
processUpdateCounts(updateCounts);
// Either commit the successfully executed statements or rollback the entire batch
connection.rollback();
} catch (SQLException e) {
}
public static void processUpdateCounts(int[] updateCounts) {
for (int i=0; i<updateCounts.length; i++) {
if (updateCounts[i] >= 0) {
// Successfully executed; the number represents number of affected rows
} else if (updateCounts[i] == Statement.SUCCESS_NO_INFO) {
// Successfully executed; number of affected rows not available
} else if (updateCounts[i] == Statement.EXECUTE_FAILED) {
// Failed to execute
}
}
}
可能会更好一些。
i number;
type id_type is table of t.object_id%type;
type name_type is table of t.object_name%type;
tid id_type := id_type();
tname name_type := name_type();
begin
SELECT object_id, object_name BULK COLLECT INTO tid, tname FROM t;
FORALL i IN tid.first .. tid.last
INSERT INTO T1 (object_id, object_name) VALUES (tid(i), tname(i));
commit;
end SP_PRE;具体做法参考文档