Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


JSP - display single record from database

Posted on 2005-05-17
Medium Priority
Last Modified: 2010-07-27
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?  
Question by:rwallacej
  • 2
LVL 29

Expert Comment

ID: 14019951
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)-->
<% } %>
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.

Author Comment

ID: 14020412
how do I get a ResultSet?  Please give an example , thanks
LVL 29

Accepted Solution

bloodredsun earned 1500 total points
ID: 14021023
Somehting like this:

      String      place;
      Connection dbconn;
      ResultSet results;
      PreparedStatement sql;
                  int      latitude,longitude,easting,northing;
                  boolean      doneheading = false;
                  dbconn = DriverManager.getConnection("jdbc:mysql://clun.scit.wlv.ac.uk/mydatabase","demo","");
                  place = request.getParameter("place");
                  sql = dbconn.prepareStatement("SELECT * FROM gazetteer WHERE feature = '" + place + "'");
                  results = sql.executeQuery();

Except you need to use the driver for Acesss having set up your datasource as an ODBC datasource.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ready to get certified? Check out some courses that help you prepare for third-party exams.
By following these Magento e-commerce development tips, you can increase your website's conversion and profitability. Read this post for more details.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses
Course of the Month11 days, 10 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question