Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQLite_在Java中的事务处理过程中忙吗?_Java_Sqlite_Jdbc_Transactions - Fatal编程技术网

SQLite_在Java中的事务处理过程中忙吗?

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

我有一个CSV文件,其中有10000多条记录,每个记录长约1000个字符,可添加到sqlite数据库中

这样做虽然有效,但速度非常慢:

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()
,您可能会更走运。我要试试,谢谢!什么都没有改变。仍在寻找解决方案