mysql - Safety of not catching SQL Exception -


let's have program puts email addresses database email attribute primary key. if have duplicate email address, deal in 2 ways.

1) run "select email table" query. if email in there, don't add it.
2) don't check if email in table. catch(sqlexception e), don't print stack trace, skip on it. way, if i'm inserting duplicate ignores it.

granted method 1, i'm executing simple select query (no joins or fancy) performance isn't huge issue. if wanted optimize performance, method 2 viable, safe way of doing this? instead of running "select ..." every time, add it.

are there safety issues skipping on exception?

java example (with jdbc):

try {     string sql = "insert emails values(?)";     preparedstatement pstmt = conn.preparestatement(sql);     pstmt.setstring(1, email);     pstmt.execute();     return true; }  catch(sqlexception e) {     // e.printstacktrace(); // skip; don't print out error     return false; } 


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -