输出数据库的表内容

 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 }

 

转载于:https://www.cnblogs.com/XuGuobao/p/7141741.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值