JDBC—批处理的基本用法
批处理的基本用法 批处理时:先把事务设置为手动提交,然后尽量使用 Statement /* * 测试批处理的基本用法 * 对于大量的批处理,建议使用Statement,因为PreparedStatement的预编译空间有限当数据量特别大时,会发生异常。 * 批处理时先把事务设置为手动提交,然后尽量使用 Statement */ public class Demo05 { public static void main ( String [ ] args ) { Connection conn = null ; Statement stmt = null ; ResultSet rs = null ; try { // 加载驱动类 Class . forName ( "com.mysql.jdbc.Driver" ) ; // 建立连接(连接对象内部其实包含了Socket对象,是一个远程的连接。比较耗时!这是Connection对象管理的一个要点!) // 真正开发中,为了提高效率,都会使用连接池来管理连接对象! conn = DriverManager . getConnection ( "jdbc:mysql://localhost:3306/testjdbc?useUnicode=true&characterEncoding=UTF-8" , "root" , "root" )