Sample.jsp
<%@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>
<form
action="store" name="frm">
<table
border="2">
<tr>
<td>Name</td>
<td><input
type="text" name="T1"/></td>
</tr>
<tr>
<td>Gender</td>
<td><input
type="text" name="T2"/></td>
</tr>
<tr>
<td>Age</td>
<td><input
type="text" name="T3"/></td>
</tr>
<tr>
<td>Address</td>
<td><input
type="text" name="T4"/></td>
</tr>
<tr>
<td>City</td>
<td><input
type="text" name="T5"/></td>
</tr>
<tr>
<td>PinCode</td>
<td><input
type="text" name="T6"/></td>
</tr>
<tr>
<td>Phone
number</td>
<td><input
type="text" name="T7"/></td>
</tr>
<tr>
<td></td>
<td><input
type="submit" name="T1"
value="Submit"/></td>
</tr>
</table>
</form>
</body>
</html>
store.java
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import
javax.servlet.ServletException;
import
javax.servlet.http.HttpServlet;
import
javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse;
public class store extends
HttpServlet {
protected void
processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException,
ClassNotFoundException, SQLException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String
s=request.getParameter("T1");
String
s1=request.getParameter("T2");
String
s2=request.getParameter("T3");
String s3=request.getParameter("T4");
String
s4=request.getParameter("T5");
String
s5=request.getParameter("T6");
String
s6=request.getParameter("T7");
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=(Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/projects","root","root");
/* using
this query for stored procedure
DELIMITER
//
CREATE PROCEDURE aa(in name varchar(50),in phone
varchar(50),in quali varchar(50))
begin
insert into adddre values(name,phone,quali);
end
//
*
*
*
*/
CallableStatement css=(CallableStatement)
con.prepareCall("{call
aa(?,?,?)}");
css.setString(1, s);
css.setString(2,
s1);
css.setString(3, s2);
//
css.setString(4, s3);
//
css.setString(5, s4);
//
css.setString(6, s5);
ResultSet
rs = (ResultSet) css.executeQuery();
while(rs.next())
{
String
ds=rs.getString(1);
System.out.println(":::::::"+ds);
String dss=rs.getString(2);
System.out.println(":::::::"+dss);
}
css.close();
System.out.println("done **********
");
response.sendRedirect("informa.jsp");
} finally {
out.close();
}
}
}
Database :
Database name :
Projects
CREATE TABLE 'address' (
'addressid' int(10) default NULL,
'city' varchar(50) default NULL,
'state' varchar(50) default NULL,
'country' varchar(50) default NULL
);
CREATE TABLE 'login' (
'AU_ID' int(11) NOT NULL auto_increment,
'uname' varchar(255) NOT NULL,
'upass' varchar(255) NOT NULL,
PRIMARY KEY ('AU_ID')
);
Create Stored
Routine :
0 comments:
Post a Comment