输出数据库的表内容
1 package org.lxh.demo17.resultsetdemo; 2 3 import java.sql.Connection; 4 import java.sql.DriverManager; 5 import java.sql.ResultSet; 6 import java.sql.Statement; 7 8 public class ResultSetDemo01 { 9 private static final String DBDRIVER = "com.mysql.jdbc.Driver"; 10 private static final String DBURL = "jdbc:mysql://localhost:3306/mldn"; 11 private static final String DBUSER = "root"; 12 private static final String DBPASS = "root"; 13 public static void main(String[] args) throws Exception { 14 Connection conn = null; 15 Statement stmt = null; 16 ResultSet rs = null; 17 String sql = "select id,name,password,age,sex,birthday from user"; 18 Class.forName(DBDRIVER); 19 conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS); 20 stmt = conn.createStatement(); 21 rs = stmt.executeQuery(sql); 22 while(rs.next()){ 23 int id = rs.getInt(1); 24 String name = rs.getString(2); 25 String pass = rs.getString(3); 26 int age = rs.getInt(4); 27 String sex = rs.getString(5); 28 java.util.Date d = rs.getDate(6); 29 30 System.out.print(id + "."); 31 System.out.print(name + "."); 32 System.out.print(pass + "."); 33 System.out.print(age + "."); 34 System.out.print(sex + "."); 35 System.out.println(d + "."); 36 37 System.out.println(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"); 38 } 39 rs.close(); 40 stmt.close(); 41 conn.close(); 42 } 43 }