
Hai ,
If u want to do simple insetion and data retrival operation throw jsp ?.you need not to bother about whole code.just u consentration on html,ajax,jsp,any db.here i am using db2.
Html for insertion:
<form name="StudentForm" method="post" action="simple.jsp">
<table border="1" width="30%">
<tr>
<td align="center" colspan="2"> <font face="Monotype" size="5">Registration</font></td>
</tr>
<tr>
<td> Student id: </td> <td> <input type="text" name="sId" size="20"></td>
</tr>
<tr>
<td> Student Name: </td> <td> <input type="text" name="sName" size="20"></td>
</tr>
<tr>
<td> Student Age: </td> <td> <input type="text" name="sAge" size="20" onKeyup="isInteger(this.value)"></td>
</tr>
<tr>
<td> Student Department: </td><td><input type="text" name="sDept" size="20" /></td>
</tr>
<tr>
<td align="center" colspan="2"> <input type="submit" value="Save" "
<input type="button" value="Cancle" >
</td>
</tr>
</table>
</form>
Jsp:Simple.jsp
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%@page import="java.sql.*"%>
<html>
<head>
</head>
<%
String sId = request.getParameter("sId");//read the data from html page and store sId variable
String sName = request.getParameter("sName");
String sAge = request.getParameter("sAge");
String sDept = request.getParameter("sDept");
String sId1 = request.getParameter("sId");
int f=Integer.parseInt(sAge);
out.println(sId);
out.println(sName);
out.println(sAge);
out.println(sDept);
out.println(f);
Connection conn = null;
ResultSet result = null;
Statement stmt = null;
String Query=" INSERT INTO STUD(S_SID,S_NAME,S_CONTACT,S_DEPT) VALUES ('"+sId+"','"+sName+"',"+f+",'"+sDept+"') ";
// out.println(Query);
try {
Class.forName("com.ibm.db2.jcc.DB2Driver");
conn = DriverManager.getConnection("jdbc:db2://59.145.105.55:50000/tsttrial","trialadm","trial123");
out.println(conn);
out.println("connection successfully");
stmt =conn.createStatement();
int r=stmt.executeUpdate(Query);
out.println("Student information successfully inserted");
}
catch (SQLException e) {
System.out.println("Error occurred " + e);
}
%>
it is enough to data insertion....From G RameshNaidu.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.