日期:2014-05-16 浏览次数:20459 次
Connection con = null; PreparedStatement sta = null; // Statement sta = null; String sql = "INSERT INTO dbbean VALUES('na','nb','nc','nd','ne','nf','ng','nh','ni','nj','nk','nl','nm');"; try { long start = System.currentTimeMillis(); Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root"); con.setAutoCommit(false); sta = con.prepareStatement(sql); System.out.println("连接数据库耗时: "+(System.currentTimeMillis()-start)+"ms"); for(int i=0;i<100000;i++){ // sta.addBatch(sql); sta.execute(); } con.commit(); System.out.println("总共用时: "+(System.currentTimeMillis()-start)+"ms"); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }
public class IBatisDAO{ public SqlSessionFactory sqlMapper; public String resource = "ibatis_conf.xml"; public void init(){ Reader reader; try { reader = Resources.getResourceAsReader(resource); sqlMapper = new SqlSessionFactoryBuilder().build(reader); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public SqlSessionFactory getSqlMapper() { this.init(); return sqlMapper; } }
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd"> <mapper namespace="net.unison.ivr"> <insert id="insert"> insert into dbbean values('na','nb','nc','nd','ne','nf','ng','nh','ni','nj','nk','nl','nm') </insert> </mapper>
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN" "http://ibatis.apache.org/dtd/ibatis-3-config.dtd"> <configuration> <environments default="development"> <environment id="development"> <transactionManager type="JDBC" /> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/test" /> <property name="username" value="root" /> <property name="password" value="root" /> </dataSource> </environment> </environments> <mappers> <mapper resource="ibatis_mapper.xml" /> </mappers> </configuration>
<insert id="insert" statementType="PREPARED"> insert into dbbean values('na','nb','nc','nd','ne','nf','ng','nh','ni','nj','nk','nl','nm') </insert>