Database
registration.jsp
<%--
Document : display
Created on : 13 Apr, 2010, 9:54:48 AM
Author : Bhasker
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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>registration</title>
</head>
<body>
<h1>registration form</h1>
<form name="registration1" action="display.jsp" method="POST">
<table border="1">
<thead>
<tr>
<th>enter information</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td><input type="text" name="n1" value="" size="30" /></td>
</tr>
<tr>
<td>city</td>
<td><input type="text" name="c1" value="" size="30" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="submit" name="b1" /></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
display.jsp
<%--
Document : display
Created on : 14 Apr, 2010, 2:38:06 PM
Author : Bhasker
--%>
<%@page import ="java.sql.*"%>
<%@page import =" java.util.*"%>
<%@page import =" java. io.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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>JSP Page</title>
</head>
<body>
<h1>registration record!</h1>
<%
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:reg");
Statement st=con.createStatement();
PreparedStatement pst=con.prepareStatement("insert into registration(name,city) values(?, ?)");
pst.clearParameters();
pst.setString(1,request.getParameter("n1"));
pst.setString(2,request.getParameter("c1") );
int i= pst.executeUpdate();
if(i>0)
{
out.println("Record Saved");
ResultSet rs=st.executeQuery("Select * from registration");
out.print("<br/>");
out.print("<table border=4>");
while(rs.next())
{
out.print("<tr bgcolor=pink>");
out.print("<td>");
out.print(rs.getString(1));
out.print("</td>");
out.print("<td>");
out.print(rs.getString(2));
out.print("</td>");
out.print("</tr>");
}
out.print("</table>");
}
else
{out.println("Record Not Saved");}
}
catch(Exception e)
{}
finally {
out.close();
}
%>
</body>
</html>
No comments:
Post a Comment