DYNAMIC HTML TABLE BINDING WITH SQL DATABASE VALUES:
<%--
Document : index
Created on : 30 Nov, 2015, 9:34:15 AM
Author : User
--%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<%
int count =0;
List<String> no=new ArrayList<String>();
List<String> data=new ArrayList<String>();
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection("Jdbc:mysql://localhost/kk","root","root");
Statement stm=con.createStatement();
ResultSet rs= stm.executeQuery("select * from pkm");
while(rs.next())
{
no.add(rs.getString("no"));
data.add(rs.getString("name"));
}
out.println("<table border='1'> <tr><td> S:NO</td><td> NAME</td></tr>");
for(int i=0;i<no.size();i++)
{
out.println("<tr><td> "+no.get(i)+"</td><td>"+data.get(i)+"</td></tr>");
}
out.println("</table>");
%>
</body>
</html>
<%--
Document : index
Created on : 30 Nov, 2015, 9:34:15 AM
Author : User
--%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<%
int count =0;
List<String> no=new ArrayList<String>();
List<String> data=new ArrayList<String>();
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection("Jdbc:mysql://localhost/kk","root","root");
Statement stm=con.createStatement();
ResultSet rs= stm.executeQuery("select * from pkm");
while(rs.next())
{
no.add(rs.getString("no"));
data.add(rs.getString("name"));
}
out.println("<table border='1'> <tr><td> S:NO</td><td> NAME</td></tr>");
for(int i=0;i<no.size();i++)
{
out.println("<tr><td> "+no.get(i)+"</td><td>"+data.get(i)+"</td></tr>");
}
out.println("</table>");
%>
</body>
</html>
No comments:
Post a Comment