<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<html>
<head>
<title>data successfully saved</title>
</head>
<body>
<% // get parameters from the request
String id = request.getParameter("id");
String name = request.getParameter("name");
String comment = request.getParameter("comment");
Statement statement = null;
// declare a connection by using Connection interface
Connection connection = null;
try {
/* Create string of connection url within specified format
with machine name,
port number and database name. Here machine name id
localhost and database name is usermaster. */
String connectionURL = "jdbc:mysql://localhost:3306/usermaster";
// Load JBBC driver "com.mysql.jdbc.Driver" by newInstance() method.
Class.forName("com.mysql.jdbc.Driver").newInstance();
/* Create a connection by using getConnection()
method that takes parameters of string type connection url, user
name and password to connect to database. */
connection = DriverManager.getConnection(connectionURL, "root", "root");
statement = connection.createStatement();
String QueryString = "INSERT INTO user_master
(user_id,name,comment) VALUES ('" +
id + "','" + name + "','" + comment + "')";
int UQ = statement.executeUpdate(QueryString);
if (UQ > 0) {
%><font color="green" size="5" >Congratulations !</font>
<h2><p>Your comment is submitted successfully.<br></p></h2>
<TABLE style="background-color: #ECE5B6;" WIDTH="30%">
<tr>
<tr>
<td>User Id</td>
<td><%= id%></td>
</tr>
<tr>
<td>Name</td>
<td><%=name%></td>
</tr>
<tr><td></td><td align="right">
<A HREF="first_page.jsp">
<font size="4" color="blue">go to home page</font></A>
</td>
</tr>
</TABLE>
<% }
} catch (Exception ex) {
%>
<FONT size="+3" color="red"></b>
<%
out.println("Unable to connect to database.");
} finally {
statement.close();
connection.close();
}
%>
</FONT>
</body>
</html>
|