SQLite_在Java中的事务处理过程中忙吗?
我有一个CSV文件,其中有10000多条记录,每个记录长约1000个字符,可添加到sqlite数据库中 这样做虽然有效,但速度非常慢:SQLite_在Java中的事务处理过程中忙吗?,java,sqlite,jdbc,transactions,Java,Sqlite,Jdbc,Transactions,我有一个CSV文件,其中有10000多条记录,每个记录长约1000个字符,可添加到sqlite数据库中 这样做虽然有效,但速度非常慢: try{ while((line = reader.readLine()) != null){ preparedStatement = connection.prepareStatement("BEGIN"); preparedStatement.execute(); //All prepared sta
try{
while((line = reader.readLine()) != null){
preparedStatement = connection.prepareStatement("BEGIN");
preparedStatement.execute();
//All prepared statements with inserts and selects
preparedStatement = connection.prepareStatement("COMMIT");
preparedStatement.execute();
}
}catch(SQLException){
preparedStatement = connection.prepareStatement("ROLLBACK");
preparedStatement.execute();
}
为了加快速度,我只想做一个事务,因此我将其更改为:
try{
preparedStatement = connection.prepareStatement("BEGIN");
preparedStatement.execute();
while((line = reader.readLine()) != null){
//All prepared statements
}
preparedStatement = connection.prepareStatement("COMMIT");
preparedStatement.execute();
}catch(SQLException){
preparedStatement = connection.prepareStatement("ROLLBACK");
preparedStatement.execute();
}
但我在大约1000次插入后得到此异常:
org.sqlite.SQLiteException:[sqlite\u BUSY]数据库文件已锁定(数据库已锁定)
这是什么?我很确定这是唯一一个使用DB的任务。我怎样才能解决它
谢谢 与其发送
BEGIN
,COMMIT
等,不如使用connection.setAutoCommit(false)
,preparedStatement.addBatch()
,preparedStatement.executeBatch()
,以及connection.COMMIT()
,我要试试看,谢谢!什么都没有改变。仍然在寻找解决方案,而不是发送BEGIN
,COMMIT
等。使用connection.setAutoCommit(false)
,preparedStatement.addBatch()
,preparedStatement.executeBatch()
,以及connection.COMMIT()
,您可能会更走运。我要试试,谢谢!什么都没有改变。仍在寻找解决方案