小demo
创建Connection对象 ,Statement对象,executeQuery(sql语句)。getString()方法 import java.util.* ; import java.sql.DriverManager ; import java.sql.Statement ; import java.sql.Connection ; import java.sql.ResultSet ; class Tester { public static final String DBDRIVER="org.gjt.mm.mysql.Driver" ; public static final String DBUSER = "root" ; public static final String DBPASS = "include" ; public static final String DBURL="jdbc:mysql://localhost:3306/student" ; public static void main(String args[]) throws Exception { Connection con = null; Statement sta=null; ResultSet rs = null; String sql = "select * from user ;" ; Class.forName(DBDRIVER) ; con=DriverManager.getConnection(DBURL,DBUSER,DBPASS) ; sta = con.createStatement() ; rs = sta.executeQuery(sql); while(rs.next()) { System.out.println("id:"+rs.getInt("id")+" 姓名:"+rs.getString("name")+" 密码") ; } sta.close(); //Connection .close(); con.close() ; } }