sybase批量insert 效率低 求解!!!

l344438713 2012-08-27 09:32:17


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秒,这个速度简直无法忍受了!!! 高手求解!!!
...全文
438 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lwb344438713 2012-08-28
  • 打赏
  • 举报
回复
不满意结贴
WWWWA 2012-08-27
  • 打赏
  • 举报
回复
你将事务打开试试,什么版本、系统
l344438713 2012-08-27
  • 打赏
  • 举报
回复
表中只有一个字段 create table GridIndex_Range (intGridIndex integer)

另外在sybase中执行下面的。1万条要25秒 太慢了吧 是不是sybase的什么配置文件没配对???

declare @i int
set @i=0
while @i<10000
begin
insert into GridIndex_Range(intGridIndex) values (@i)
set @i=@i+1
end



结果
1 条记录受到影响


1 条记录受到影响


1 条记录受到影响

感觉没有批量?????
WWWWA 2012-08-27
  • 打赏
  • 举报
回复
表中有多少字段、记录,你将id保存在表中,直接插入不行?
l344438713 2012-08-27
  • 打赏
  • 举报
回复
sybase IQ
网上查了下 insert的确慢,使用 load table 较快 但是我调试下面的语句,每次都是: 0 条记录受到影响
txt中就是数字然后换行
求解!!



set temporary option CONVERSION_ERROR='OFF';
load table GridIndex_Range
(
intGridIndex 'x0a'
)
From
'E:\gridindex.txt'
ESCAPES OFF
QUOTES OFF
NOTIFY 1000000
ON FILE ERROR CONTINUE
IGNORE CONSTRAINT ALL 0
WITH CHECKPOINT OFF;
commit;

2,598

社区成员

发帖
与我相关
我的任务
社区描述
Sybase相关技术讨论区
社区管理员
  • Sybase社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧