02-17-2012 04:06 AM - edited 02-17-2012 04:13 AM
Hi All,
I know there are a few threads about this but they appear to be dead. I have attached a very simple and crued application hightlighting my problem. Click the button and it will start the transactions.
The problem im having is i am getting large amounts of transaction (batches of 250 transactions) from a server to be applied to a database, inserts updates deletes etc. It works for a while but will then blow with the out of memory exceptions. The number of transactions can be reduced but even doing 1 transaction per batch will result in the error.
The application is doing to be used for 5.0 devices and higher any help would be greatly appreciated.
Cheers
PS. I no there is suggestions of using System.gc() but that will that not have major problems on the performs.
Solved! Go to Solution.
02-17-2012 08:40 AM
You created a bunch of statements each time you call the execute method. Test change your fieldChanged event to :
public void fieldChanged(Field field, int context) {
try {
database.beginTransaction();
statement = database.createStatement("INSERT INTO TEST (ID, VALUE) VALUES(?,?)");
statement.prepare();
label.setText("INSERTING...");
StringBuffer sb =new StringBuffer();
for(int i = 0; i < 100000; i++) {
sb.append("Value ").append(i);
st.bind(1, sb.toString());
st.bind(2, i);
st.execute();
st.reset();
sb.setlength(6) ; // "Value " length
}
st.close();
database.commitTransaction();
database.close();
} catch (DatabaseException e) {
label.setText(e.getMessage());
e.printStackTrace();
}
}
HTH
02-17-2012 09:28 AM - edited 02-17-2012 09:30 AM
Ok i will try that but what if the statements change tables?
Would i have an extra variable inside the statement then for the table name like
INSERT INTO ? VALUES(?, ?) etc
02-17-2012 09:40 AM
I think you can not do that. Instead could be something like this:
StringBuffer sb = new StringBuffer(1024);
sb.append("INSERT INTO ").append(tableName);
sb.append(" VALUES(?, ?) ");
String sql = sb.toString();
Maybe you can use a Hashtable to store the fieldname and fieldtype in order to do the field binding and generate the needed "?" in the sql insert statement.
02-20-2012 03:02 AM