© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
Quick Links
Easy Studies

Retrieve data from database and display it in JSP file


This program is to display the database contents on the JSP page. Using the data source name as bankdomain application is connected with the database. From the given table all rows and column names are collected using the interface ResultSet.From the ResultSet object, row count is calculated. getMetaData () method get the column name and column count. Using the loop we can print the column name inside the <tr>and <td> tag until the column count. Likewise rows are also displayed.

Retrieve data from database and display it in JSP file:

<%@ page import="java.sql.*"%> MSACCESS QUERY FORM


User details


<% int l=0; int rowcu=0; int totalRecords=0; ResultSetMetaData rsmt=null; ResultSet datars=null; String query="select * from bank1"; //String query = (String)session.getAttribute("query"); //String user = (String)session.getAttribute("user"); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cot=DriverManager.getConnection("jdbc:odbc:bankdomain","scott","tiger"); Statement stmtt=cot.createStatement(); Statement rowc=cot.createStatement(); Statement datas=cot.createStatement(); ResultSet resultt=stmtt.executeQuery(query); ResultSet resucourow=datas.executeQuery(query); int x=0; while(resucourow.next()){ x++; } resultt.next(); rsmt=resultt.getMetaData(); l=rsmt.getColumnCount(); System.out.println("Column Count"+l); System.out.println("Column Count Rowssss "+x); datars=rowc.executeQuery(query); } catch(Exception e1){ } %> <%for(int v=1;v<=l;v++){System.out.println("l value"+l);String cnames=rsmt.getColumnName(v);%> <%}%> <% while(datars.next()){%> <%for(int vc=1;vc<=l;vc++){%> <% } }%>

Sample ScreenShot:

SLogix Student Projects

⇓Student Projects⇓
⇑Student Projects⇑