Closed Gronis closed 8 years ago
Nevermind. I managed to figure out how to do it :) Just wrap everything inside a transaction and it works ^^
db.withVoidTransaction(t -> {
try {
ResultTable rt = db.findTable("select * from SomeTable");
} catch (Exception e){
db.update("create table SomeTable (field int)");
}
});
Hi,
That would be one solution, but it could hide some other problems as well. Furthermore, errors when executing SQL could mark the running transaction to be rolled back at the end, causing problems.
Depending on your situation, it's probably better to either query the _informationschema (or use java.sql.DatabaseMetaData
) to check the presence of the table or simply use the "if not exist" -variant for the "create table". So it could be as simple as executing this:
db.update("create table if not exist SomeTable(field int)");
Yes, you are probably right. That is a better solution. Thanks! :)
EDIT: Answer below!
Hi nice lib you have here!
I have a question regarding exceptions. If I example do this:
An exception is still printed to the console (see print below). Somehow my catch does not "catch" the exception. However the table is still created so it somehow catches the exception. My question is that why is the exception still printed to my console of the exception is handled?
Print:
I'm using mysql (as you can tell by the exception log)