I have a table in mysql which I can view perfectly using JSP, but there is a problem with inserting into the table which I cannot figure out.
Here is my code:
<%@ include file = "database_ini.jsp"%>
<%
if(request.getParameter("insert") != null){
String name = request.getParameter("name");
String sql = "insert into testdata (name) values ('" + name + "')";
int a = stmt.executeUpdate(sql);
out.print("Insert success");
}
%>
<html>
<head>
<title>Insert</title>
</head>
<body>
<form action = "insert11.jsp" method = "post">
Name : <input type = "text" name = "name" size = "10">
<br/>
<input type = "submit" name = "insert" value = "Insert">
</form>
<a href="index11.jsp">index</a>
</body>
</html>
And, here is my error:
org.apache.jasper.JasperException: An exception occurred processing JSP page /insert11.jsp at line 8
5: String name = request.getParameter("name");
6:
7: String sql = "insert into testdata (name) values ('" + name + "')";
8: int a = stmt.executeUpdate(sql);
9: out.print("Insert success");
10:
11:
Any help would be greatly appreciated. Thanks