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