Hi all,
This is my code,
public static boolean updateDB() {
Connection cn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
boolean result = false;
int number;
String insetSQL ="update quan set ten_quan='lin' where id=1";
try {
cn = LocalDatabasePooling.getInstance().getConnection();
pstmt = cn.prepareStatement(insetSQL);
pstmt.executeUpdate();
result = true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException sqle) { }
}
if (pstmt != null) {
try {
pstmt.close();
}
catch (SQLException sqle) { }
}
if (cn1 != null) {
try {
cn1.close();
}
catch (SQLException sqle) { }
}
}
return false;
}
Is the code above correct? But when I debug, I saw that the line
number = pstmt.executeUpdate();
was not executed and the code below it were not executed too.
when I add watch
pstmt.executeUpdate();
I saw this info
error(during the evaluation
What is wrong?
Apparently an exception was been thrown which was completely ignored by your code. Something like:
You should at least log/print the stacktrace
Or, even better, just throw it.
Exceptions contain a wealth of information about the cause of the problem and they should not be ignored, unless you really know what you’re doing.