TY_BCA_2015_ADV_JAVA_15MARKS_SLIP20



SLIP 20:  Write a JSP program to display the details of Hospital (HNo, HName, Address) in tabular form on browser
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<html><body>
<%@ page import="java.sql.*;" %>
<%! int hno;
String hname,address;  %>
<%

try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection cn=DriverManager.getConnection("jdbc:odbc:hospital_data","","");

            Statement st=cn.createStatement();
            ResultSet rs=st.executeQuery("select * from Hospital");
            %>
                        <table border="1" width="40%">
                        <tr>
                        <td>Hospital No</td>
                        <td>Name</td>
                        <td>Address</td>
                        </tr>
                        <%      while(rs.next())
                        {
                                    %>
                                                <tr> <td><%= rs.getInt("hno") %></td>
                                                <td><%= rs.getString("hname") %></td>
                                                <td><%= rs.getString("address") %></td>
                                                </tr>
                                                <%
                        }
            cn.close();
}catch(Exception e)
{      
            out.println(e);      
}
%>
</body></html>

No comments:

Post a Comment