Retrieve Data from Oracle database using JSP

Here in this context we have a database and the database contain some data. We will develop a JSP application and when it will execute, we will retrieve the data from database.
Let we have a student table containing some records.
Friends, before going to the development, first we have to know we are using Oracle10g / 11g XE database and we are using Eclipse environment and our server is web server that is Apache Tomcat9.0
Step-1: First in Oracle environment we will create a Student Table:
create table Student
(
sregdno varchar2(200),
sname varchar2(200),
saddress varchar2(200)
);
Output
Table created.

Now we inserted 3 records and the output like:

Jsp Retrieve data

Step-2: Now we will go to eclipse environment and we will develop 2 JSP files, like index.jsp and retrieve.jsp

Required Files:
index.jsp
retrieve,jsp
index.jsp
<html>
<body>
<form action="retrieve.jsp">
            Please enter the regdno:
            <BR>
            <INPUT TYPE="TEXT" NAME="regdno">
            <BR>
            <INPUT TYPE="SUBMIT" value="Submit">
        </FORM>
</body>
</html>

retrieve.jsp
<%@ page import="java.sql.*" %>
<body>
<%

Class.forName("oracle.jdbc.driver.OracleDriver");           
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle");

Statement st = con.createStatement();

String id = request.getParameter("regdno"); 

ResultSet rs = st.executeQuery("select * from Student where sregdno = '" + id + "'") ;

if(!rs.next()) {
                out.print("Sorry, could not find therecord. ");
            } else {
        %>

        <TABLE BORDER="1">
            <TR>
               <TH>sregdno</TH>
               <TH>sname</TH>
               <TH>saddress</TH>
           </TR>
           <TR>
               <TD> <%= rs.getString(1) %> </TD>
               <TD> <%= rs.getString(2) %> </TD>
               <TD> <%= rs.getString(3) %> </TD>
           </TR>
       </TABLE>
       <BR>
       <%
           }
       %>
</body>
</html>

Output

jsp dataretrieve

Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Projects

SILAN Technology
Call to: 9439202111  |  9658317757  |  0674-2361252

Comment