Wednesday, 3 May 2023

Write a JSP program to display the details of College (CollegeID, Coll_Name, Address) in tabular form on browser.

 Write a JSP program to display the details of College (CollegeID, Coll_Name,

Address) in tabular form on browser.


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

<html>

<head>

<title>College Details</title>

</head>

<body>

<h1>College Details</h1>

<table border="1">

<tr>

<th>College ID</th>

<th>College Name</th>

<th>Address</th>

</tr>

<%

try {

   

    Class.forName("com.mysql.jdbc.Driver");

    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/collegedb", "root", "password");

     Statement stmt = con.createStatement();

    ResultSet rs = stmt.executeQuery("SELECT CollegeID, Coll_Name, Address FROM College");

     while (rs.next()) {

        %>

        <tr>

        <td><%= rs.getString("CollegeID") %></td>

        <td><%= rs.getString("Coll_Name") %></td>

        <td><%= rs.getString("Address") %></td>

        </tr>

        <%

    }

 

   

    rs.close();

    stmt.close();

    con.close();

} catch (Exception e) {

    out.println("Error: " + e.getMessage());

}

%>

</table>

</body>

</html>