One, the code is as follows
private void Select_mysql () {//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) {//TODO auto-generated catch Blocke.printstacktrace ();} finally {try {rs.close (); Cn.close ();} catch ( SQLException e) {e.printstacktrace ();}}}
MySQL database __jdbc direct Operation __preparedstatement__select