The example explains how to use JSP to obtain the data in the ResultSet result set, and the example describes the resultset

Source: Internet
Author: User

The example explains how to use JSP to obtain the data in the ResultSet result set, and the example describes the resultset

Obtain all records

<% @ Page language = "java" contentType = "text/html; charset = gb2312" %> <% @ page import = "java. SQL. *" %> <! DOCTYPE html> 

Obtain records of specified fields in all records

<% @ Page language = "java" contentType = "text/html; charset = gb2312" %> <% @ page import = "java. SQL. *" %> <! DOCTYPE html> 

Obtain the record of the specified start position and number of entries

<% @ Page language = "java" contentType = "text/html; charset = gb2312" %> <% @ page import = "java. SQL. *" %> <! DOCTYPE html> 

Traverse the data in the ResultSet and convert it to a table
After searching for the data in the ResultSet on the Internet for a long time and filling it in a webpage table in sequence, it is said that the ResultSet data is converted to a two-dimensional array and then output in sequence, however, the storage size of the two arrays needs to be specified in advance, which is inconvenient for amplification. Use the following method:

while(rs.next()){    out.println("<tr><td>"+rs.getString(1)+"</td><td>" +rs.getString(2)+"</td><td>"+rs.getString(3)+"</td><td>"        +rs.getString(4)+"</td><td>"+rs.getString(5)+"</td><td>"+rs.getString(6)+"</td><td>"        +rs.getString(7)+"</td><td>"+rs.getString(8)+"</td><td>"+rs.getString(9)+"</td><td>"        +rs.getString(10)+"</td><td>"+rs.getString(11)+"</td><td>"+rs.getString(12)+"</td><tr>");}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.