JDBC: Performing query operations with ResultSet

Source: Internet
Author: User


Package Xuezaipiao2;import Java.sql.connection;import Java.sql.resultset;import java.sql.statement;import Xuezaipiao1. Jdbc_tools;public class Useresultand {public static void main (string[] args) {/** * ResultSet (Result set): Encapsulates the structure of queries using JDBC. * 1. Call the Statement object's executequery (SQL) to get the result set * 2.ResultSet is actually a data table, a pointer to the first item of the data table, the front * Next () method is used to determine whether there is a next piece of data, Similar to iterator * 3. When the pointer is pointing to a row, you can get the value of the specified column by GETXXX (index) or getXxx (ColumnLabel) *, and getInt (1) Gets the value of the first column, and getString ("name") gets the The alias is the value of the column of name * 4. ResultSet also need to close */connection conn = null; Statement Statement = null; ResultSet rs = null;try {conn = jdbc_tools.getconnection (); statement = Conn.createstatement (); String sql = "SELECT * FROM Customer",//string sql = "Select Id,name,email from customer where id = 4"; rs = statement.exec Utequery (SQL), while (Rs.next ()) {System.out.println (Rs.getint ("id")); System.out.println (rs.getstring (2)); System.out.println (rs.getstring ("email"));}} catch (Exception e) {e.printstacktrace ();} Finally{jdbc_tools.relasesourCE (RS, conn, statement);}}} 


JDBC: Performing query operations with ResultSet

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.