sybase批量insert 效率低 求解!!!
public void insertGridIndex(Jsoner query){
List<Map<String,Integer>> gridList = (List<Map<String,Integer>>)query.root().get("gridIndexRange").getArray() ;
int size = gridList.size();
long time = System.currentTimeMillis();
Connection conn = null;
Statement stmt = null;
PreparedStatement pstmt = null;
try{
conn = DbUtil.getInstance().getConnection();
conn.setAutoCommit(false);
stmt = conn.createStatement();
stmt.execute("if exists (select 1 from sys.SYSTABLE where table_name ='GridIndex_Range') then drop table GridIndex_Range end if");
stmt.execute("create table GridIndex_Range (intGridIndex integer)");
String sql = "insert into GridIndex_Range(intGridIndex) values (?)";
System.out.println("SQL = "+sql);
pstmt = conn.prepareStatement(sql);
int batch = 0;
for(int i=0;i<size;i++){
pstmt.setInt(1,gridList.get(i).get("id").intValue());
pstmt.addBatch();
batch++;
if(batch==2000){
pstmt.executeBatch();
conn.commit();
pstmt.clearBatch();
batch = 0;
}
}
pstmt.executeBatch();
conn.commit();
pstmt.clearBatch();
System.out.println("---------传入大小-----------:"+size);
System.out.println("-----------耗时-------------:"+(System.currentTimeMillis()-time));
}catch (SQLException ex) {
ThrowPrintUtils.throwDaoExceptionSql(ex);
} catch (Exception ex) {
ThrowPrintUtils.throwDaoException(ex);
} finally {
if(pstmt != null){
try{
pstmt.close() ;
pstmt= null;
}catch(SQLException e){
e.printStackTrace() ;
}
}
if(stmt != null){
try{
stmt.close() ;
stmt = null;
}catch(SQLException e){
e.printStackTrace() ;
}
}
if(conn != null){
try{
conn.close() ;
conn = null;
}catch(SQLException e){
e.printStackTrace() ;
}
}
}
}
问题:现在在内存中有一批id,向一个表中插入,我按照上面的方法,2000条提交一次,3万条竟然要150秒,这个速度简直无法忍受了!!! 高手求解!!!
...全文
相关推荐
sybase的安装及配置
sybase安装完成后的一个简单的配置,如何新建数据,如何启动服务,如何新建设备,如何用sybase central连接到服务器,以及如何使用bcp命令
sybase数据库的基本语法
sybase的基础语法包括select ,insert,update,delete,创建表,删除表,创建数据库,游标,数据库设备等
Sybase中文手册
Embedded SQLC开发手册 .pdf sybase命令详解.pdf Sybase语法大全.pdf 数据类型、系统函数、错误代码.pdf 系统表.pdf 系统过程.pdf
sybase ADO
是sybase关于ado的资料,希望有帮助
sybase数据库jdbc驱动jar包
需要使用jdbc连接sybase数据库的同学们可以下载使用了


