Contact Us
JSP Tutorial
JDBC Tutorial
Book Must Read

JDBC Display Record

Print   Email

JDBC select

This will get records from database and print and view on JSP page. The SQL query is used as select command statement, and with while loop we can view all records in table.

Example of select record in database through JSP

Database Table

CREATE TABLE  staff_register (
  `iEmpID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `sStaffName` varchar(60) DEFAULT NULL,
  `sStaffDept` varchar(45) DEFAULT NULL,
  `iStaffPhone` int(10) unsigned DEFAULT NULL,
  UNIQUE KEY `sStaffName` (`sStaffName`)


HTML Code Example

<%@ page language="java" import="java.sql.*" errorPage="" %>
        Connection conn = null;
        String jdbcURL="jdbc:mysql://localhost:3306/databaseName";
        conn = DriverManager.getConnection(jdbcURL,"username", "password");
        PreparedStatement psSelectRecord=null;
        ResultSet rsSelectRecord=null;
        String sqlSelectRecord=null;
        sqlSelectRecord ="SELECT * FROM staff_register";
<title>View records in JSP through database</title>

<h1>View Record from Database through JSP</h1>

S. No |  EmpID | Staff Name | Staff Department | Staff Phone <br>
  int cnt=1;
   cnt++;   /// increment of counter
  } /// End of while loop

        catch(Exception e)




If You Like this Article, share this

  Privacy Policy