日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網(wǎng)為廣大站長提供免費收錄網(wǎng)站服務(wù),提交前請做好本站友鏈:【 網(wǎng)站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(wù)(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747


 

我們在日常開發(fā)中,經(jīng)常會用到一個系統(tǒng)需要鏈接多個數(shù)據(jù)庫來實現(xiàn)業(yè)務(wù)的需求,比如多個系統(tǒng)之間數(shù)據(jù)調(diào)用、兩個數(shù)據(jù)之間同步等等。

今天給大家分享使用Hutool-db實現(xiàn)多數(shù)據(jù)源配置,大家一起來學(xué)習(xí)一下吧!

1、hutool-db介紹

Hutool-db是一個在JDBC基礎(chǔ)上封裝的數(shù)據(jù)庫操作工具類,通過包裝,使用ActiveRecord思想操作數(shù)據(jù)庫。在Hutool-db中,使用Entity(本質(zhì)上是個Map)代替Bean來使數(shù)據(jù)庫操作更加靈活,同時提供Bean和Entity的轉(zhuǎn)換提供傳統(tǒng)ORM的兼容支持。


 

1. 數(shù)據(jù)源 DataSource

2. SQL執(zhí)行器 SQLExecutor

3. CRUD的封裝 Db、sqlConnRunner SqlRunner

4. 支持事務(wù)的CRUD封裝 Session

5. 各種結(jié)果集處理類 handler

6. 數(shù)據(jù)庫的一些工具方法匯總 DbUtil

2、新建一個Maven項目2.1 導(dǎo)入依賴包

MySQLmysql-connector-JAVA5.1.45com.microsoft.SqlServersqljdbc44.0cn.hutoolhutool-db5.7.22com.alibabadruid1.2.92.2 新建db.setting配置文件

src/main/resources/config/db.setting

[mysql]url = jdbc:mysql://127.0.0.1:3306/mydb?characterEncoding=utf-8&useSSL=false&serverTimezone=GMTusername = rootpassword = 123456driver = com.mysql.jdbc.Driver[sqlserver]url = jdbc:sqlserver://192.168.33.4:1433;DatabaseName=DBusername = sapassword = 123456driver = com.microsoft.sqlserver.jdbc.SQLServerDriver2.3 新建測試demo

* 測試mysqlprivate static void testMysql() {DataSource ds = DSFactory.get("mysql");Db.use(ds);Connection conn = null;try {conn = ds.getConnection();// 插入語句SqlExecutor.execute(conn, "insert into t_user (name,age) value ('小張',35)");// 更新語句SqlExecutor.execute(conn, "update t_user set name='小明002' where id=2 ");// 刪除語句SqlExecutor.execute(conn, "delete from t_user where id=2 ");List entityList = SqlExecutor.query(conn, "select * from t_user limit 50", new EntityListHandler());for (Entity entity : entityList) {System.out.println(entity.get("name"));} catch (SQLException e) {} finally {DbUtil.close(conn);* 測試sqlserverprivate static void testSqlServer() {DataSource ds = DSFactory.get("sqlserver");Connection conn = null;try {conn = ds.getConnection();List entityList = SqlExecutor.query(conn, "select * from t_user", new EntityListHandler());for (Entity entity : entityList) {System.out.println(entity.get("username"));} catch (SQLException e) {} finally {DbUtil.close(conn);* 直接代碼寫jdbc數(shù)據(jù)源 不推薦的方式private static void testDefineJdbc() {DruidDataSource ds = new DruidDataSource();ds.setUrl("jdbc:mysql://127.0.0.1:3306/mydb?characterEncoding=utf-8&useSSL=false&serverTimezone=GMT");ds.setUsername("root");ds.setPassword("12345678");Connection conn = null;try {conn = ds.getConnection();List entityList = SqlExecutor.query(conn, "select * from t_user", new EntityListHandler());for (Entity entity : entityList) {System.out.println(entity.get("name"));} catch (SQLException e) {} finally {DbUtil.close(conn);

分享到:
標(biāo)簽:hutool db
用戶無頭像

網(wǎng)友整理

注冊時間:

網(wǎng)站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨大挑戰(zhàn)2018-06-03

數(shù)獨一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學(xué)四六

運動步數(shù)有氧達(dá)人2018-06-03

記錄運動步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績評定2018-06-03

通用課目體育訓(xùn)練成績評定