Link to home
Start Free TrialLog in
Avatar of rwallacej
rwallacej

asked on

JSP - display single record from database

I have a jsp which needs to be populated with values from a query in an Access database. The query only returns one row.
My jsp consists of text boxes which need to be filled with the fields in the query.

How is this done?  
Avatar of bloodredsun
bloodredsun
Flag of Australia image

<html>
<body>
<%
ResultSet rs = //from your Access db
%>
<% while ( rs.next() ){//move resultset onto the next row %>
A line of db stuff <%= rs.getString("id") %><!-- get by column name -->
A line of db stuff <%= rs.getString(2) %><!-- get by column index (start from 1)-->
<% } %>
</body>
</html>
-------------
When you get a resultset, you need to call rs.next() as a query returns a resultset witht cursor positioned before the first row initially. This method works for single or multiple rows.
Avatar of rwallacej
rwallacej

ASKER

how do I get a ResultSet?  Please give an example , thanks
ASKER CERTIFIED SOLUTION
Avatar of bloodredsun
bloodredsun
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial