JDBC議答侃尖荷恬眉嶽圭塀
扮寂:2011-04-03 51cto鴬人 leizhimin
SQL答侃尖頁JDBC來嬬單晒議嶷勣冷匂?将云繁冩梢悳潤?答侃尖議喘隈嗤眉嶽。
package lavasoft.jdbctest;
import lavasoft.common.DBToolkit;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
/**
* JDBC議答楚荷恬眉嶽圭塀
*
* @author leizhimin 2009-12-4 14:42:11
*/
public class BatchExeSQLTest {
public static void main(String[] args) {
exeBatchStaticSQL();
}
/**
* 答楚峇佩圓協吶庁塀議SQL
*/
public static void exeBatchParparedSQL() {
Connection conn = null;
try {
conn = DBToolkit.getConnection();
String sql = "insert into testdb.book (kind, name) values (?,?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "java");
pstmt.setString(2, "jjjj");
pstmt.addBatch(); //耶紗匯肝圓協吶歌方
pstmt.setString(1, "ccc");
pstmt.setString(2, "dddd");
pstmt.addBatch(); //壅耶紗匯肝圓協吶歌方
//答楚峇佩圓協吶SQL
pstmt.executeBatch();
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBToolkit.closeConnection (conn);
}
}
/**
* 答楚峇佩詞栽庁塀議SQL、嗤圓協吶議?珊嗤床蓑議
*/
public static void exeBatchMixedSQL() {
Connection conn = null;
try {
conn = DBToolkit.getConnection();
String sql = "insert into testdb.book (kind, name) values (?,?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "java");
pstmt.setString(2, "j
|