Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/purvgwtw/public_html/tutorials/common.php on line 7
Retrieve data from the database using JSP
Sponsered Links
Categories
Sponsered Links

Retrieve data from the database using JSP

This section demonstrates you how to retrieve all the data from the database table using JSP.

<%@ page import="java.sql.*" %>
<table border="1">
<tr><th>Name</th><th>Address</th></tr>
<%
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement st= conn.createStatement();
ResultSet rs = st.executeQuery("select * from data");

while(rs.next())
{
%>
<tr><td><%=rs.getString("name")%></td><td><%=rs.getString("address")%></td></tr>
<%
}
}
catch (Exception e) {
e.printStackTrace();
}
%>
</table>

Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2014 PURVACOMPUTERS.COM All Right Reserved