首页 > 代码库 > 输出数据库的表内容
输出数据库的表内容
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 }
输出数据库的表内容
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。