JDBC Connectivity
<%@page import="java.sql.*" %>
<%@page import="java.io.*" %>
<html>
<head><title> Display data from Employee Table in JSP </title></head>
<body>
<%
try
{
//Declare the con using Connection Interface
Connection con=null;
//Declare stml object of Statment Interface , this will help to execute the Sql Query
Statement stmt=null;
//Declare rs using ResultSet which will use to display the table data
ResultSet rs=null;
// Loading JDBC Driver
Class.forName("com.mysql.jdbc.Driver").newInstance();
//Creating connection with Database using Driver Manager
con=DriverManager.getConnection("jdbc:mysql://172.16.100.8:3306/rkmishradb", "rkmishra","a");
//CreateSstement() methods will help to create sql statement which will sent specified Database
stmt=con.createStatement();
//Executing SQL Query
rs=stmt.executeQuery("select *from emp");
%>
<table border="1" align="center">
<tr>
<td>Emp ID</td>
<td>Emp Name </td>
<td> Department</td>
</tr>
<%
while(rs.next())
{
%>
<tr>
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%> </td>
<td> <%=rs.getString(3)%></td>
</tr>
<%}
%>
</table>
<%
rs.close();
stmt.close();
con.close();
}
catch(Exception e)
{
out.println("Unable to Connect");
}
%>
</body>
</html>