写入的行少于SQLite预期的行

时间:2011-06-23 07:05:11

标签: java sqlite

当我执行超过1,00,215行的插入操作时,它只写入1,00,105行。

缓冲区或缓存有问题吗?如果这个问题那么如何增加内存的大小呢?

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import com.csvreader.CsvReader;

public class CSVStoreData 
{
    Connection con=null;
    ResultSet rs=null;
    Statement smt = null;

    public void insertData(String path) 
    {
        try
        {
            Class.forName("SQLite.JDBCDriver");
            con = DriverManager.getConnection("jdbc:sqlite:/D:\\DB\\Mediation.db");
            con.setAutoCommit(false);
            smt = con.createStatement();
            CsvReader filereader = new CsvReader(path,',');
            filereader.readHeaders();
            long startTime = System.currentTimeMillis();
            while(filereader.readRecord())
            { 
                String query="insert into CDRData values('"+filereader.get(0)+"','"+filereader.get(1)+"','"+filereader.get(2)+"','"+filereader.get(3)+"','"+filereader.get(4)+"','"+filereader.get(5)+"','"+filereader.get(6)+"','"+filereader.get(7)+"','"+filereader.get(8)+"','"+filereader.get(9)+"','"+filereader.get(10)+"','"+filereader.get(11)+"','"+filereader.get(12)+"','"+filereader.get(13)+"','"+filereader.get(14)+"','"+filereader.get(15)+"','"+filereader.get(16)+"','"+filereader.get(17)+"','"+filereader.get(18)+"','"+filereader.get(19)+"','"+filereader.get(20)+"','"+filereader.get(21)+"','"+filereader.get(22)+"')";
                //System.out.println(filereader.get(0)+","+filereader.get(1)+","+filereader.get(2)+","+filereader.get(3)+","+filereader.get(4)+","+filereader.get(5)+","+filereader.get(6)+","+filereader.get(7)+","+filereader.get(8)+","+filereader.get(9)+","+filereader.get(10)+","+filereader.get(11)+","+filereader.get(12)+","+filereader.get(13)+","+filereader.get(14)+","+filereader.get(15)+","+filereader.get(16)+","+filereader.get(17)+","+filereader.get(18)+","+filereader.get(19)+","+filereader.get(20)+","+filereader.get(21)+","+filereader.get(22));
                smt.executeUpdate(query);
                // System.out.println("\n");
            }
            System.out.println("Record Inserted");
            long finishTime = System.currentTimeMillis();
            System.out.println("The time taken by insert query : "+(finishTime-startTime)+ " ms");
            con.commit();
        }
        catch(Exception e)
        {
            System.out.println("Error ---- "+e);
        }
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        CSVStoreData csvdata = new CSVStoreData();
        csvdata.insertData("D:\\CDRfile\\110527_160001.cdr");
    }
}

1 个答案:

答案 0 :(得分:1)

您可能超过了SQLite数据库的最大大小。查看http://www.sqlite.org/limits.html(具体来说,最后两段)。虽然您确实没有超过表中的最大行数,但根据您的最大页数和页面大小设置,您可能会超出最大数据库大小。

http://www.sqlite.org/pragma.html#pragma_max_page_counthttp://www.sqlite.org/pragma.html#pragma_page_size也可能有用。

注意检查这些值并告诉我们你得到了什么?