<%@ page import = "java.sql.*" %>
<%
Connection con = null; PreparedStatement pstmt = null;
String SQL = "INSERT INTO employees (emp_no, birth_date, first_name, last_name, gender, hire_date) VALUES (?,?,?,?,?,?,);
try { Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/employees", "root", "password");
con.setAutoCommit(false);
pstmt = con.prepareStatement(SQL);
Savepoint savepoint1 = con.setSavepoint("Savepoint1");
pstmt.setInt(1, 9000);
pstmt.setString(2, "2020-04-04");
pstmt.setString(3, "John");
pstmt.setString(4, "Joe");
pstmt.setString(5, "M");
pstmt.executeUpdate();
con.commit();
out.println("Record is added.");
out.println("<br/>");
} catch (Exception e) {
con.rollback(savepoint1);
out.println(e.getMessage());
} finally {
con.setAutoCommit(true);
}
} %>
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: [38] in the jsp file: [/transaction_pstmt.jsp]
savepoint1 cannot be resolved to a variable35:
36: } catch (Exception e){
37:
38: con.rollback(savepoint1);
39:
40: out.println(e.getMessage());
41:
And, This is error message. What's the problem?
Thanks in advance.