SQLite - executeUpdate exception not caught when database does not exist? (Java)

Posted by giant91 on Stack Overflow See other posts from Stack Overflow or by giant91
Published on 2013-09-24T16:40:36Z Indexed on 2013/10/22 3:54 UTC
Read the original article Hit count: 81

Filed under:
|
|
|

So I was purposely trying to break my program, and I've succeeded.

I deleted the sqlite database the program uses, while the program was running, after I already created the connection. Then I attempted to update the database as seen below.

Statement stmt;
try
{
    stmt = Foo.con.createStatement();
    stmt.executeUpdate("INSERT INTO "+table+" VALUES (\'" + itemToAdd + "\')");
}
catch(SQLException e)
{
    System.out.println("Error: " + e.toString());
}

The problem is, it didn't catch the exception, and continued to run as if the database was updated successfully. Meanwhile the database didn't even exist at that point since this was after I deleted it.

  • Doesn't it check if the database still exists when updating?
  • Do I have to check the database connection manually, every time I update to ensure that the database wasn't corrupted/deleted?
  • Is this the way it is normally done, or is there a simpler/more robust approach?

Thank you.

© Stack Overflow or respective owner

Related posts about java

Related posts about database