A read a lot of stuff, like here: SQLite queries much slower using JDBC than in Firefox SqliteManager plugin
But I have no clue what's the problem. The case is, I have a SQLite database (from an Android tablet) and a not too large table (~50.000 rows in it) If I run a "select * from table" for example in Sqlite Manager it takes 0.11 sec, correct.
But... if I do it in a Java program (with SQLite JDBC) it takes 20 minutes!!! Not kidding.
Somebody (somewhere) said it depends on the versions. But my question is how?
Because this command: "SELECT sqlite_version()" gives different results on the same .db file in every case:
- in a very old sqlite manager it gives 3.6.19
- in Sqlite Studio 3.15
- and in with the newest .exe from sqlite.org it gives 3.23.1 So it's not a database related thing, I think it's the version of the sqlite3.exe used.
I can change the JDBC driver all day long (I did it a few times), but how would I know which I needed?
Anybody with any thought? I'm totally stucked with it.
EDIT: Okay, so JDBC jars are from here: https://bitbucket.org/xerial/sqlite-jdbc/downloads/
And my code is really basic, at first I just wanted to measure the speed.
Class.forName("org.sqlite.JDBC");
Connection c1 = DriverManager.getConnection("jdbc:sqlite:" + "c:\\database.db");
PreparedStatement stmt1 = c1.prepareStatement("select * from table1;");
ResultSet rs = stmt1.executeQuery();
String script = "insert into table1 values ";
while (rs.next()) {
script += "(";
script += rs.getInt(1) + ", '" + rs.getString(2) + "', '" + rs.getString(3) + "'";
script += "),";
}
stmt1.close();
c1.close();
And the executeQuery() row takes 20 minutes.