import java.sql.Connection;Import Java.sql.drivermanager;import java.sql.resultset;import java.sql.sqlexception;import java.sql.Statement; public class Sqldemo {public static void Main (string[] args) {try {//1, load driver//Driver name: Com.mysql.jdbc.DriverClass.forName ("Com.mysql.jdbc.Driver");//2, establishment and database connection//sql user name: Root//sql user password: 8273322Connection con = drivermanager.getconnection ("Jdbc:mysql://127.0.0.1:3306/store?characterencoding=utf8&usessl=false", "root", "8273322");//(1) Find operation:String sql = "SELECT * from Good_list";/* Statement is an important interface for Java to perform database operations.used to send the SQL statement to be executed to the database, based on the database connection already established. Statement object for executing simple SQL statements with no arguments*/Statement stmt = Con.createstatement ();/*ResultSet, a data table for a database result set, typically generated by executing statements that query the database. */ResultSet rs = stmt.executequery (SQL);//Traversal outputwhile (Rs.next ()) {//or: Int id = rs.getint ("id"); ID is data segment nameint id = rs.getint (1);String name = rs.getstring (2);String pw = rs.getstring (3);System.out.println (id+ "" +name+ "" +PW ");}//OffRs.close ();Stmt.close ();Con.close ();} catch (ClassNotFoundException e) {E.printstacktrace ();} catch (SQLException e) {E.printstacktrace ();}}}
Database Lookup Operation-java