Recently, due to the needs of the project, it is necessary to improve the data warehouse receiving performance in the project. Through optimization, it is found that the warehouse receiving method is different, and the efficiency is really quite different.
The initial code is as follows: Execute SQL statements directly, and add transactions to improve performance:
Java code
- Sqlitedatabase database = new sqlitedatabase ();
- If (database. isopen ())
- {
- Database. begintransaction ();
- Try {
- // The SQL statement is insert into tablename (name) values ("test ")
- Database.exe csql (SQL );
- }
- Database. settransactionsuccessful ();
- } Finally {
- Database. endtransaction ();
- }
- Database. Close ();
- }
The optimization is as follows:
Java code
- Sqlitedatabase database = new sqlitedatabase ();
- // SQL is insert into tablename (name) values (?)
- Sqlitestatement sqlliststatment = database. compilestatement (SQL );
- If (database. isopen ())
- {
- Database. begintransaction ();
- Try {
- // The index starts from 1 and the value is the value of the database.
- // Bingxxx is the insert XXX type
- Sqlitestatement. bindstring (index, value );
- Sqlitestatement.exe cuteinsert ();
- }
- Database. settransactionsuccessful ();
- } Finally {
- Database. endtransaction ();
- }
- Database. Close ();
- }
From http://woodn-z.iteye.com/blog/1447719