In my app there are some threads that access the database and control this competition using the lock from totalcross.
My question is: Can I allow exceptions to be thrown within a synchronized block? or do I have to do something to get the exception thrown out of its scope?
Today I prevent this from happening.
Here is an example code used:
public int executeUpdate(int dbIdx, String sql) {
int res = 0;
// secure access for database resource
synchronized (MainDB.lockDB) {
try {
Debug.debug(sql, Debug.DEBUG_LEVEL_DEBUG);
// Create statement to execute query
Statement st = connPool[dbIdx].createStatement();
// Execute query
res = st.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return res;
}