#===================================================================
# pom.xml中添加引用
# <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
# <dependency>
# <groupId>mysql</groupId>
# <artifactId>mysql-connector-java</artifactId>
# <version>8.0.17</version>
# </dependency>
#
# <!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
# <dependency>
# <groupId>com.microsoft.sqlserver</groupId>
# <artifactId>mssql-jdbc</artifactId>
# <version>7.4.0.jre12</version>
# <scope>test</scope>
# </dependency>
# 数据库配置文件样例
# \src\main\resources目录下创建config/db.setting
# DsFactory默认读取的配置文件是config/db.setting
# db.setting的配置包括两部分:基本连接信息和连接池配置信息。
# 基本连接信息所有连接池都支持,连接池配置信息根据不同的连接池,连接池配置是根据连接池相应的配置项移植而来
#=================================================================== ## db.setting文件
#mysql
#url = jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false
#driver =com.mysql.cj.jdbc.Driver
#sqlserver
url = jdbc:sqlserver://111.230.23.148:1433; DatabaseName=SampleDB
driver =com.microsoft.sqlserver.jdbc.SQLServerDriver user = sa
pass = Smile2017AbC_168_bCd8690
## 可选配置
# 是否在日志中显示执行的SQL
showSql = true
# 是否格式化显示的SQL
formatSql = false
# 是否显示SQL参数
showParams = true

  

package com.database.demo;

import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import java.sql.SQLException;
import java.util.List; @RunWith(SpringRunner.class)
@SpringBootTest
public class DemoApplicationTests { @Test
public void contextLoads() {
} @Test
public void Test1() throws SQLException {
//product为表名
// List<Entity> list = Db.use().findAll("product");
// for (Entity entity : list) {
// System.out.println(entity.toString());
// } // 直接sql语句操作 insert/update/delete
// Integer i = Db.use().execute("insert into product(username,password,realname) values(?,?,?)", "zhangxiao", "1234568", "张晓");
// if (i > 0) {
// System.out.println("数据插入成功");
// } else {
// System.out.println("数据插入失败");
// }
Entity entity = Entity.create("product");
List<Entity> list = Db.use().page(entity, 2, 10);
for (Entity entity1 : list) {
//System.out.println(entity1.toString());
System.out.printf("用户ID: %s 用户名:%s 真实姓名:%s", entity1.get("id"), entity1.get("username"), entity1.get("realname"));
System.out.println();
} } }

  

package com.database.demo.model;

public class Product {

    private int id;
private String username;
private String password;
private String realname; public Product(int id, String username, String password, String realname) {
this.id = id;
this.username = username;
this.password = password;
this.realname = realname;
} public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String getRealname() {
return realname;
} public void setRealname(String realname) {
this.realname = realname;
} @Override
public String toString() {
return "Product{" +
"id=" + id +
", username='" + username + '\'' +
", password='" + password + '\'' +
", realname='" + realname + '\'' +
'}';
}
}

最新文章

  1. redis数据结构存储Linked List设计细节(redis的设计与实现笔记)
  2. nginx配置ssl证书的方法
  3. js压缩图片base64长度
  4. MySql的max_connections和max pool的设置
  5. 【Visual Lisp】图元选择集专题
  6. ural 2065. Different Sums
  7. linux多种安装包格式的安装方法
  8. 中国大数据六大技术变迁记(CSDN)
  9. [摘]PE中安装Windows 7/8
  10. use worker without js file
  11. 折腾slidingmenu
  12. Android编程获取网络连接状态(3G/Wifi)及调用网络配置界面
  13. 《Hexo+github搭建个人博客》
  14. 在线预览pdf、xlsx、docx、ppt等文档
  15. android 实践项目
  16. Linux操作系统进程模型分析进程
  17. PyJWT 使用
  18. NET设计模式 第二部分 行为型模式(18):观察者模式(Observer Pattern)
  19. C#调用C++Dll封装时遇到的一系列问题
  20. Java锁的设计

热门文章

  1. vue-ueditor-wrap报错,vue ueditor 加载ueditor.config.js失败,请检查您的配置地址UEDITOR_HOME_URL填写是否正确!
  2. nodejs之express的中间件
  3. Eclipse上安装websphere
  4. 阿里云给自己实例扩容-扩展分区和文件系统_Linux系统盘
  5. [Jenkins][centos]1 持续集成 之 配置VNC,部署Jenkins
  6. Vue 前后端分离系统中遇到跨域问题
  7. P2882 [USACO07MAR]Face The Right Way [贪心+模拟]
  8. python 查询每周最后一个工作日
  9. js 面向对象之构造器与工厂函数
  10. GIT的创建和使用