The full results of the database can be queried using the SELECT statement in SQL, and all query records for the database are received using ResultSet in JDBC operations, and the content is displayed using ResultSet.
Querying data from the user table
=================================================//File name:mysql_demo//------------------------------------ ------------------------------------------//Author:commonimport java.sql.*;//main class//function:mysql_demopu Blic class Mysql_demo {//Database driver to define MySQL public static final String dbdriver = "org.gjt.mm.mysql.Driver";// Define the connection address of the MySQL database public static final String Dburl = "Jdbc:mysql://localhost:3306/mysql_demo"; connection user name for//mysql database public Static final String DBUSER = "root"; connection password for//mysql database public static final String dbpass = "123456";p ublic static void Main (St Ring[] args) throws Exception {//TODO automatically generated method stub connection conn = null;//database connection Statement stmt = null;//database operation ResultSet rs = null;//save query result String sql = "Select id,name,password,age,sex,birthday from User"; Class.forName (dbdriver);//Load driver//connection to MySQL database, write the username and password of the connection conn = Drivermanager.getconnection (dburl,dbuser,dbpass ); stmt = Conn.createstatement ();//Instantiate Statement Object rs = stmt.executequery (sql);//Instantiate ResultSet object while (Rs.nexT ()) {int id = rs.getint ("id"); String name = rs.getstring ("name"); String pass = rs.getstring ("password"); int = Rs.getint ("Age"); String sex = rs.getstring ("Sex");D ate d = rs.getdate ("Birthday"); System.out.println ("Number:" +id); System.out.println ("Name:" +name); System.out.println ("Password:" +pass); System.out.println ("Age:" +age); System.out.println ("Gender:" +sex); System.out.println ("Birthday:" +d);} Rs.close (); Close result set Stmt.close (); Operation off Conn.close (); Database Close}}
Java Database--resultset Interface