I have a JSP file that gets forms from an HTML file and sends them to an SQL database. here are the files:
attempt.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="attempt.jsp" method="post">
<input type="text" name="fname"></input> name
<input type="text" name="age"></input> age
<input type="submit"></input>
</form>
</body>
</html>
attempt.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/DB","root","060901");
PreparedStatement st = con.prepareStatement("insert into tb values(?,?);");
st.setString(1,request.getParameter("fname"));
int a = Integer.parseInt(request.getParameter("age"));
st.setInt(2,a);
int num = st.executeUpdate();
ResultSet res = st.executeQuery("select * from tb;");
res.beforeFirst();
%>
<table>
<%
while(res.next()) {
%>
<tr>
<td><%=res.getString("name") %></td>
<td><%=res.getInt("age") %></td>
</tr>
<%
}
%>
</table>
</body>
</html>
I am quite new to the subject of servers and databases, so I have a hard time cracking this one. The MySQL-connector jar is already in the buildpath and I have already tried importing it to the JSP page. Does anyone know what to do?
Thanks in advance.