標籤:pre block ext mysql microsoft roo 資料庫 dstat result
一、代碼如下
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");ps = 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資料庫__Jdbc直接操作__PreparedStatement__select