jdbc,采用properties文件保存数据库账号密码以及链接
时间:2021-07-01 10:21:17
帮助过:34人阅读
package com.sogood.jdbc;
2
3 import com.sogood.util.SqlUtil;
4
5 import java.sql.Connection;
6 import java.sql.ResultSet;
7 import java.sql.SQLException;
8 import java.sql.Statement;
9
10 public class Demo {
11 public static void main(String[] args)
throws SQLException {
12 query();
13 }
14
15 private static void query() {
16 Connection con =
null;
17 Statement stm =
null;
18 ResultSet rs =
null;
19 try {
20 con =
SqlUtil.getConnection();
21 String sql = "SELECT * FROM STUDENT"
;
22 stm =
con.createStatement();
23 rs =
stm.executeQuery(sql);
24 System.out.println("查询结果:"
);
25 while (rs.next()) {
26 int id = rs.getInt("id"
);
27 System.out.println("id = " +
id);
28 }
29 }
catch (Exception e) {
30 e.printStackTrace();
31 }
finally {
32 SqlUtil.close(con, stm, rs);
33 }
34 }
35 }
jdbc,采用properties文件保存数据库账号密码以及链接
标签:数据 文件 连接 final test pack rgs com blog