<%@page
language="java" import="java.sql.*"%>
<%@page contentType="text/html"
pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta
http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>JSP
Page</title>
</head>
<body>
<h2>JDBC
Programe</h2>
<table>
<%-- <% String
DRIVER="sun.jdbc.odbc.JdbcOdbcDriver";--%>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection con=null;
ResultSet rst=null;
Statement stmt=null;
try{
String
url="jdbc:odbc:HOD_DATA";
con=DriverManager.getConnection(url,"root","");
stmt=con.createStatement();
rst=stmt.executeQuery("select * from data");
if(rst.next()){
%>
<table
border="1">
<th>ID</th>
<th>Name</th>
<th>City</th>
<tr>
<td><%=
rst.getInt("ID")%></td>
<td><%=
rst.getString("Name")%></td>
<td><%=
rst.getString("City")%></td>
</tr>
<% while(rst.next()){%>
<tr>
<td><%=
rst.getInt("ID")%></td>
<td><%=
rst.getString("Name")%></td>
<td><%=
rst.getString("City")%></td>
</tr>
<%}%>
</table>
<% }
else
{
%>
<p> Sorry, Query return no
rows</p>
<% }
rst.close();
stmt.close();
}
catch(SQLException
e)
{
out.println("there was
Error");
}
%>
</table>
</body>
</html>
Output
:
No comments:
Post a Comment