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

x
?
Solved

JSP - display single record from database

Posted on 2005-05-17
3
Medium Priority
?
221 Views
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?  
0
Comment
Question by:rwallacej
  • 2
3 Comments
 
LVL 29

Expert Comment

by:bloodredsun
ID: 14019951
<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.
0
 

Author Comment

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

Accepted Solution

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

--------
<%
      String      place;
      Connection dbconn;
      ResultSet results;
      PreparedStatement sql;
      try
      {
            Class.forName("org.gjt.mm.mysql.Driver");
            try
            {
                  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();
                  while(results.next())
                  {
//blah
//blah

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

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