Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 491
giant91 Avatar asked Nov 12 '22 21:11

giant91


1 Answers

Interestingly, I found that if I delete my database when using it and then attempt to update it, it updates the database in its new location (in the trash!). You cannot permanently delete it while it is in the trash can and you are accessing it via your program.

like image 152
giant91 Avatar answered Nov 15 '22 00:11

giant91