Hi friend,
<html>
<head>
<title>Insert into database</title>
</head>
<body>
<table border="1" width="50%" bgcolor="lightgreen">
<tr>
<td width="100%">
<form method="POST" action="insertAction.jsp">
<h2 align="center">Insert User Information page</h2>
<table border="1" width="100%">
<tr>
<td width="50%"><b>User ID:</b></td>
<td width="50%"><input type="text" name="userid" size="5"/> </td>
</tr>
<tr>
<td width="50%"><b>User Name:</b></td>
<td width="50%"><input type="text" name="username" size="20"/> </td>
</tr>
<tr>
<td width="50%"><b>Address:</b></td>
<td width="50%"><input type="text" name="address" size="50"/> </td>
</tr>
<tr>
<td width="50%"><b>Position:</b></td>
<td width="50%"><input type="text" name="position" size="20"/> </td>
</tr>
<tr>
<td width="50%"><b>Salary:</b></td>
<td width="50%"><input type="text" name="salary" size="20"/> </td>
</tr>
</table>
<p><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset"></p>
</form>
</td>
</tr>
</table>
</body>
</html>
-------------------------------------
<%@ page language="java" import="java.sql.*" %>
<%
Connection con = null;
String url = "jdbc:
mysql://192.168.10.211:3306/";;
String db = "amar";
String driver = "com.mysql.jdbc.Driver";
String userName ="amar";
String password="amar123";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,userName,password);
try{
Statement st = con.createStatement();
String userid=request.getParameter("userid");
String username = request.getParameter("username");
String address =request.getParameter("address");
String position = request.getParameter("position");
String salary = request.getParameter("salary");
int val = st.executeUpdate("insert Information values('"+userid+"','"+username+"','"+address+"','"+position+"','"+salary+"')");
con.close();
out.println("successfully insert data into database!");
}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
%>
------------------------------
Read for more information.
http://www.roseindia.net/jsp/Thanks.