Commit 1c1a5b7e by OscarGonzalez97

ejemplo sql con jsp

parent 6703c9ff
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Open Account</title>
</head>
<body>
<form action="openaccount.jsp" method="post">
<input type="text" name="accno" />
<input type="text" name="lastname" />
<input type="text" name="firstname" />
<input type="text" name="bal" />
<input type="submit" />
</form>
</body>
</html>
\ No newline at end of file
<%@ page import="java.sql.*" language="java"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%!
Connection con;
PreparedStatement ps;
public void jspInit() {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/mydb", "root", "test");
ps = con.prepareStatement("insert into account value(?,?,?,?)");
} catch (Exception e) {
e.printStackTrace();
}
}
public void jspDestroy() {
try {
ps.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}%>
<%
int accno = Integer.parseInt(request.getParameter("accno"));
String lastName = request.getParameter("lastname");
String firstName = request.getParameter("firstname");
int bal = Integer.parseInt(request.getParameter("bal"));
ps.setInt(1, accno);
ps.setString(2, lastName);
ps.setString(3, firstName);
ps.setInt(4, bal);
ps.executeUpdate();
%>
<%@ include file="openaccount.html" %>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment