insert data in database through jsp.with apache tomcat.

1-First of you have to install apache.
2-create folder in web-app(Rename as u want).
3-and then create folder in web-app as WEB_INF.
4-into WEB-INF---create Classes lib and one web.xml.



index.jsp



<html>
<head>
<title><center>FORM</center></title>
</head>
<body>
<center>
<form action="insert.jsp" method="post">
<table border="2">
<tr>
<td>EMPID:</td>
<td><input type="text" name="id"/></td>
</tr>
<tr>
<td>NAME:</td>
<td><input type="text" name="name"/></td>
</tr>
<tr>
<td>PASSWORD:</td>
<td><input type="text" name="pass"/></td>
</tr>
<tr>
<td>EMAILID:</td>
<td><input type="text" name="mail"/></td>
</tr>
<tr>

<td><input type="SUBMIT" value="submit"/></td>
</tr>
</table>
</form>
</center>
</body>
</html>



insert.jsp




<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>

<%
try
{
int id=Integer.parseInt(request.getParameter("id"));
String name=request.getParameter("name");
String pass=request.getParameter("pass");
String email=request.getParameter("mail");
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/naveen","root","");
PreparedStatement pst=con.prepareStatement("insert into department values(?,?,?,?)");
pst.setInt(1,id);
pst.setString(2,name);
pst.setString(3,pass);
pst.setString(4,email);
int i=pst.executeUpdate();
if(i>0)
{
%>
<a href="view.jsp">View All Records</a>
<%
}
else
{

%>
<jsp:forward page="form.jsp"></jsp:forward>
<%
}
}
catch(Exception e)
{
System.out.println(e);
}
%>


Popular posts from this blog

Simple Sign up design. Android.

Cart page design in android.

Set Date on jDateChooser and retrieve record from database.