One, the code is as follows
Package Www.tanniu.jdbc;import Java.sql.drivermanager;import Java.sql.resultset;import java.sql.SQLException; Import Com.mysql.jdbc.connection;import Com.mysql.jdbc.preparedstatement;public class JDBC {public static void main ( String[] args) {//TODO auto-generated method stubjava.sql.PreparedStatement ps= null;java.sql.connection cn= null; ResultSet rs= null;try {//class.forname ("com.microsoft.jdbc.sqlserver.SQLServerDriver"); Class.forName ("Com.mysql.jdbc.Driver"). newinstance (); cn= drivermanager.getconnection ("Jdbc:mysql://localhost : 3306/learn?user=root&password=&useunicode=true&characterencoding=utf8 ");p s= cn.prepareStatement (" SELECT * from user "), rs= ps.executequery ();//rs.next ();//system.out.println (Rs.getint (1)); while (Rs.next ()) {String Name= rs.getstring (2); String passwd= rs.getstring (3); String phone= rs.getstring (4); String email= rs.getstring (5); SYSTEM.OUT.PRINTLN (name + "+ passwd +" "+ phone +" + email);//system.out.println (name);}} catch (Exception e) {//TODOAuto-generated catch Blocke.printstacktrace ();} Finally {try {rs.close (); Cn.close ();} catch (SQLException e) {e.printstacktrace ()}}}}
MySQL database __jdbc direct Operation __statement__select