From 1c1a5b7e1cb1fe4157051e23ac99ed7766cc151c Mon Sep 17 00:00:00 2001 From: OscarGonzalez97 Date: Fri, 1 Jul 2022 12:12:31 -0400 Subject: [PATCH] ejemplo sql con jsp --- src/main/webapp/openaccount.html | 16 ++++++++++++++++ src/main/webapp/openaccount.jsp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/main/webapp/openaccount.html create mode 100644 src/main/webapp/openaccount.jsp diff --git a/src/main/webapp/openaccount.html b/src/main/webapp/openaccount.html new file mode 100644 index 0000000..acd37d2 --- /dev/null +++ b/src/main/webapp/openaccount.html @@ -0,0 +1,16 @@ + + + + +Open Account + + +
+ + + + + +
+ + \ No newline at end of file diff --git a/src/main/webapp/openaccount.jsp b/src/main/webapp/openaccount.jsp new file mode 100644 index 0000000..50fd864 --- /dev/null +++ b/src/main/webapp/openaccount.jsp @@ -0,0 +1,52 @@ +<%@ 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" %> + + + + + + + + -- libgit2 0.26.0