mysql-connector 下载
MySQL :: Download Connector/J 下载
基本步骤:
---- 加载驱动
---- 获取连接
---- 执行sql语句(成功则执行下一步,失败则回滚,涉及数据库知识)
---- 关闭连接
com.mysql.cj.jdbc.Driver;
java.sql.Connection;
import java.sql.DriverManager;
java.util.Properties; // 配置文件 – 解决普通编程的硬编码问题
@Test
void testConnect01(){
// 连接准备
// 数据库地址
String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=true";
// 登录信息
Properties properties = new Properties();
properties.setProperty("user","root");
properties.setProperty("password","020517");
//设置时区避免操作时间不符实际
properties.setProperty("serverTimezone","Asia/Shanghai");
Connection connect = null;
try {
// 加载数据库驱动
Driver driver = new com.mysql.cj.jdbc.Driver();
connect = driver.connect(url, properties); // 建立连接
System.out.println(connect);
} catch (SQLException e) {
e.printStackTrace();
}finally {
if(connect!=null){
try {
connect.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
参数解读:
url :
数据库连接地址
格式:协议+请求地址+数据库+一系列参数 (类似于网页get请求)参数使用?…&… 形式拼接,
useUnicode=true&characterEncoding=utf8&useSSL=true :
支持中文编码,指定字符集,使用SSL安全协议
dirver.connect(String url,Properties info); //获取连接的方法,及参数
user + password :登录数据库的账号密码
serverTimezone :时区,8.0版本后不设置时区可能会出现数据库显示时间和真实修改时间不一致,通常使用:Asia/Shanghai
@Test
void testConnect02(){
// 连接准备
// 数据库地址
String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=true";
// 登录信息
Properties properties = new Properties();
properties.setProperty("user","root");
properties.setProperty("password","020517");
//设置时区避免操作时间不符实际
properties.setProperty("serverTimezone","Asia/Shanghai");
// 定义驱动变量
Driver driver = null ;
Connection connect = null ;
try {
// 反射加载驱动
Class<?> clazz = Class.forName("com.mysql.cj.jdbc.Driver");
driver = (Driver) clazz.getConstructor().newInstance();
connect = driver.connect(url, properties); // 建立连接
System.out.println(connect);
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException | SQLException e) {
e.printStackTrace();
}finally {
if(connect!=null){
try {
connect.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
@Test
void testConnect03(){
// 连接准备
// 数据库地址
String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=true";
// 登录信息
Properties properties = new Properties();
properties.setProperty("user","root");
properties.setProperty("password","020517");
//设置时区避免操作时间不符实际
properties.setProperty("serverTimezone","Asia/Shanghai");
// 定义驱动变量
Driver driver = null ;
Connection connection = null ;
try {
// 反射拿到驱动
Class<?> clazz = Class.forName("com.mysql.cj.jdbc.Driver");
driver = (Driver) clazz.getConstructor().newInstance();
// 注册驱动
DriverManager.registerDriver(driver);
// 获取连接
connection = DriverManager.getConnection(url, properties);
System.out.println(connection);
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException | SQLException e) {
e.printStackTrace();
}
finally {
if(connect!=null){
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
参数解读:
DriverManager.registerDriver(driver); 驱动注册方法
DriverManager.getConnection(url, properties);//获取连接方法,与driver.connect 参数一致
@Test
void testConnect04(){
// 连接准备
// 数据库地址
String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=true";
// 登录信息
Properties properties = new Properties();
properties.setProperty("user","root");
properties.setProperty("password","020517");
//设置时区避免操作时间不符实际
properties.setProperty("serverTimezone","Asia/Shanghai");
Connection connection = null ;
try {
connection = DriverManager.getConnection(url, properties); //建立连接
System.out.println(connection);
} catch (SQLException e) {
e.printStackTrace();
}finally {
if(connection!=null){
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
不加载驱动的原因:
在com.mysql.cj.jdbc 类中,已经使用静态代码块自动对驱动进行了加载
package com.mysql.cj.jdbc; import java.sql.DriverManager; import java.sql.SQLException; public class Driver extends NonRegisteringDriver implements java.sql.Driver { public Driver() throws SQLException { } static { try { DriverManager.registerDriver(new Driver()); } catch (SQLException var1) { throw new RuntimeException("Can't register driver!"); } } }
@Test
void testConnect05(){
// 连接准备
// 数据库地址
String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=true&serverTimezone=Asia/Shanghai";
// 登录信息
String user = "root";
String password = "020517";
Connection connection = null ;
try {
// 加载数据库驱动 + 可以不写,但习惯写上!!!
Class.forName("com.mysql.cj.jdbc.Driver");
// 建立连接
connection = DriverManager.getConnection(url, user,password);
System.out.println(connection);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}finally {
if(connection!=null){
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
可以看到:
DriverManager.getConnection除了url + properties 之外
具有一个重载方法:
参数列表为: String url ,String user ,String password
同样也可以发现:
时区参数可以拼接在请求连接url后面,同理:用户名和密码也可以以明文方式拼接,但一般不这么干
硬编码:参数写在程序中写死
我们可以将请求参数写在配置文件中,在程序需要修改时 ,只需对配置文件内容进行修改即可
配置文件:
jdbc.Driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=true&serverTimezone=Asia/Shanghai
jdbc.user=root
jdbc.password=020517
java代码:
@Test
void testConnect06(){
Properties properties = new Properties();
Connection connection = null ;
try {
// 使用类加载器加载配置文件,填写配置文件所在的类路劲
// 我这里放在项目资源文件夹下,文件名为:jdbc.properties
properties.load(this.getClass().getResourceAsStream("jdbc.properties"));
String driver = properties.getProperty("jdbc.Driver");
String url = properties.getProperty("jdbc.url");
String user = properties.getProperty("jdbc.user");
String password = properties.getProperty("jdbc.password");
// 加载数据库驱动
Class.forName(driver);
// 通过DriverManage获取驱动
connection = DriverManager.getConnection(url, user,password);
System.out.println(connection);
} catch (ClassNotFoundException | SQLException | IOException e) {
e.printStackTrace();
}finally {
if(connection!=null){
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
java.sql.Statement; // 执行sql语句的对象,方法如下
statement.execute(sql); // 执行sql – 返回 boolean – 成功与否 – 一般用于 创建 & 删除 ,常用于删除
statement.executeQuery(sql); // 执行 查询sql语句 DQL
statement.executeUpdate(sql); // 执行 增删改sql语句 DML , 返回一个int值,代表受到影响的行数
statement.executeBatch(); // 执行 批量 sql
java.sql.ResultSet; // 执行sql返回数据集的对象 DML语句
@Test
void testInsert(){
Properties properties = new Properties();
Connection connection = null ;
Statement statement = null ;
try {
properties.load(this.getClass().getResourceAsStream("jdbc.properties"));
String driver = properties.getProperty("jdbc.Driver");
String url = properties.getProperty("jdbc.url");
String user = properties.getProperty("jdbc.user");
String password = properties.getProperty("jdbc.password");
// 加载数据库驱动
Class.forName(driver);
// 通过DriverManage获取驱动
connection = DriverManager.getConnection(url, user,password);
statement = connection.createStatement();
//编写sql
String sql = "insert into `student` (`name`,`pwd`,`sex`,`birthday`,`address`,`email`) values ('ywj','020517','男','2002-05-17 12:00:00','陕西','[email protected]')";
int cl = statement.executeUpdate(sql);
if(cl>0){
System.out.println("插入成功!");
}else{
System.out.println("插入失败!");
}
} catch (ClassNotFoundException | SQLException | IOException e) {
e.printStackTrace();
}finally {
if(statement!= null){
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(connection!=null){
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
@Test
void testInsert(){
Properties properties = new Properties();
Connection connection = null ;
Statement statement = null ;
try {
properties.load(this.getClass().getResourceAsStream("jdbc.properties"));
String driver = properties.getProperty("jdbc.Driver");
String url = properties.getProperty("jdbc.url");
String user = properties.getProperty("jdbc.user");
String password = properties.getProperty("jdbc.password");
// 加载数据库驱动
Class.forName(driver);
// 通过DriverManage获取驱动
connection = DriverManager.getConnection(url, user,password);
statement = connection.createStatement();
//编写sql
String sql = "delete from `student` where `name`='ywj'"; // 使用该语句删除,不会重置字段的自增量
int cl = statement.executeUpdate(sql);
if(cl>0){
System.out.println("删除成功!");
}else{
System.out.println("删除失败!");
}
} catch (ClassNotFoundException | SQLException | IOException e) {
e.printStackTrace();
}finally {
if(statement!= null){
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(connection!=null){
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
执行结果
@Test
void testInsert(){
Properties properties = new Properties();
Connection connection = null ;
Statement statement = null ;
try {
properties.load(this.getClass().getResourceAsStream("jdbc.properties"));
String driver = properties.getProperty("jdbc.Driver");
String url = properties.getProperty("jdbc.url");
String user = properties.getProperty("jdbc.user");
String password = properties.getProperty("jdbc.password");
// 加载数据库驱动
Class.forName(driver);
// 通过DriverManage获取驱动
connection = DriverManager.getConnection(url, user,password);
statement = connection.createStatement();
//编写sql
String sql = "update `student` set `name`='王刚' where `name` = 'ywj' ";
int cl = statement.executeUpdate(sql);
if(cl>0){
System.out.println("修改成功!");
}else{
System.out.println("修改失败!");
}
} catch (ClassNotFoundException | SQLException | IOException e) {
e.printStackTrace();
}finally {
if(statement!= null){
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(connection!=null){
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
@Test
void testSelect(){
Properties properties = new Properties();
Connection connection = null ;
Statement statement = null ;
ResultSet resultSet = null ;
try {
properties.load(this.getClass().getResourceAsStream("jdbc.properties"));
String driver = properties.getProperty("jdbc.Driver");
String url = properties.getProperty("jdbc.url");
String user = properties.getProperty("jdbc.user");
String password = properties.getProperty("jdbc.password");
// 加载数据库驱动
Class.forName(driver);
// 通过DriverManage获取驱动
connection = DriverManager.getConnection(url, user,password);
statement = connection.createStatement();
String sql = "select * from `student`"; // 查询所有
resultSet = statement.executeQuery(sql); // 返回结果集
while(resultSet.next()){
System.out.println((resultSet.getObject("id")+" "+resultSet.getObject("name")+" "+ resultSet.getObject("pwd")));
}
} catch (ClassNotFoundException | SQLException | IOException e) {
e.printStackTrace();
}finally {
if(resultSet!=null){
try {
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(statement!= null){
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(connection!=null){
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
ORM(Object Relational Mapping) ,是一种程序设计技术,用于实现面向对象编程语言里不同类型系统类型系统的数据之间的转换。
Java是一门面向对象的编程语言,我们查询数据库的目的,最终肯定是将数据封装成一个一个的对象 ,通过操作对象的方式来操作数据
真实的应用中,肯定不会有把数据查出来,然后打印输出的操作…
实现思想
在Java中,我们将万事万物都看作是一个一个的对象,提取他们的属性行为,编写一个个的类。
那对于关系型数据库来说,在遵循三大范式的前提下所创建的表,每一个字段之间都是密切相关的
在此基础上:
我们就可以将一张表看作一个类,每一个字段,对应这个类的一个属性,每一行数据,我们就可以通过这个类来构建一个实现对象,最终达到数据库与java的对象关系映射
表单 | 类型 | java属性 | 类型 |
---|---|---|---|
表名 student | 类名 Student | ||
id | int | id | Integer |
name | varchar | name | String |
pwd | varchar | pwd | String |
sex | varchar | sex | Character |
birthday | datetime | birthday | Date |
address | varchar | address | String |
varchar | String |
import java.sql.Date;
/**
* Author : YWJ
* Date : 2023/3/4
*/
public class Student {
private Integer id ;
private String name ;
private String pwd ;
private Character sex ;
private Date birthday ;
private String address ;
private String email ;
public Student(Integer id, String name, String pwd, Character sex, Date birthday, String address, String email) {
this.id = id;
this.name = name;
this.pwd = pwd;
this.sex = sex;
this.birthday = birthday;
this.address = address;
this.email = email;
}
public Student() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public Character getSex() {
return sex;
}
public void setSex(Character sex) {
this.sex = sex;
}
public Date getDate() {
return birthday;
}
public void setDate(Date birthday) {
this.birthday = birthday;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "Student{" +
"id=" + id +
", name='" + name + '\'' +
", pwd='" + pwd + '\'' +
", sex=" + sex +
", date=" + birthday +
", address='" + address + '\'' +
", email='" + email + '\'' +
'}';
}
}
@Test
void testSelectORM(){
Properties properties = new Properties();
Connection connection = null ;
Statement statement = null ;
ResultSet resultSet = null ;
List<Student> students = new ArrayList<>();
Student student = null ;
try {
properties.load(this.getClass().getResourceAsStream("jdbc.properties"));
String driver = properties.getProperty("jdbc.Driver");
String url = properties.getProperty("jdbc.url");
String user = properties.getProperty("jdbc.user");
String password = properties.getProperty("jdbc.password");
// 加载数据库驱动
Class.forName(driver);
// 通过DriverManage获取驱动
connection = DriverManager.getConnection(url, user,password);
statement = connection.createStatement();
String sql = "select * from `student`";
resultSet = statement.executeQuery(sql);
while(resultSet.next()){
Integer id = resultSet.getInt("id"); //推荐使用字段名查询,如果设置别名,则应使用别名
String name = resultSet.getString("name");
String pwd = resultSet.getString("pwd");
Character sex = resultSet.getString("sex").charAt(0);
Date birthday = resultSet.getDate("birthday");
String address = resultSet.getString("address");
String email = resultSet.getString("email");
student = new Student(id,name,pwd,sex,birthday,address,email);
students.add(student);
}
} catch (ClassNotFoundException | SQLException | IOException e) {
e.printStackTrace();
}finally {
if(resultSet!=null){
try {
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(statement!= null){
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(connection!=null){
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
students.forEach(System.out::println);
}
执行结果
由此可见,成功将数据信息,封装成一个一个Java对象。
-- 我们模拟一个登录系统的 用户查询
select `name` , `password` from `tableName` where `name` = ' 用户名' and `password` = '密码' ;
-- 假如我们让用户键入一个 用户名和密码,然后将他们拼接到这条语句上,以此查询,有结果则登陆成功
// 在java中,按照上面的例子,我们可能这么写
Scanner sc = new Scanner (System.in);
System.out,println("用户名:");
String user = sc.nextLine().trim();
System.out,println("密码:");
String password = sc.nextLine().trim();
String sql = "select `name` , `password` from `tableName` where `name` = '"+ user +"' and `password` = '"+ password +"' ";
select `user` , `password` from `tableName` where `user` = '乱写一个 ' or true #' and `password` = '随便写个密码';
显而易见,当我输入的user是:“乱写一个 ' or true #” 的时候利用sql语句的“or true“ 再加上一个注释符”#“,就可以做到令这句sql永远都存在结果。这就是sql注入的漏洞
java 为了避免sql注入的出现,
包装了一个全新的类PreparedStatement
,用来替代Statement
,
他们的用法是完全一样的,唯一不同的
就是sql指令的拼接方法
获取PreparedStatement对象 ----- 使用Connection 对象的prepareStatement(String sql)方法。
利用PreparedStatement,创建sql语句
使用”?“进行占位,什么意思?请看下列
/* 最终的样子 select `name` , `password` from `tableName` where `name` = ' 用户名' and `password` = '密码' ; */ // 以前的写法 String sql = "select `name` , `password` from `tableName` where `name` = '"+ user +"' and `password` = '"+ password +"' "; // 现在的写法,使用?占位 String sql = "select `name` , `password` from `tableName` where `name` = ? and `password` = ? ";
PreparedStatement ps = connection.prepareStatement(sql);
ps.setObject(插入位置,插入的值);
// 位置从1开始 ,例如
ps.setObject(1,"root");
ps.setObject(2,"123456");
// 通过一下方法执行
ps.executeUpdate(); // 增删改
ps.executeQuery(); // 查
上文中有大量的关闭连接操作,实际应用中,可以将关闭操作封装在一个工具类中,需要时直接调用。
获取连接
package com.jdbc.tools;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
/**
* Author : YWJ
* Date : 2023/3/5
* 获取连接 工具类
*/
public class GetJdbcConnectionTool {
public static Connection getJdbcConnect(){
Properties properties = new Properties();
Connection connection = null ;
try {
properties.load(GetJdbcConnectionTool.class.getClassLoader().getResourceAsStream("jdbc.properties"));
// 加载驱动
Class.forName(properties.getProperty("jdbc.Driver"));
String url = properties.getProperty("jdbc.url");
String user = properties.getProperty("jdbc.user");
String password = properties.getProperty("jdbc.password");
// 建立连接
connection = DriverManager.getConnection(url, user, password);
} catch (IOException | ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
return connection ;
}
}
资源关闭
package com.jdbc.tools;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* Author : YWJ
* Date : 2023/3/5
* jdbc资源关闭工具类
*/
public class ResourcesCloseTool {
public static void closeResources(Connection co , PreparedStatement ps , ResultSet rs){
if(rs != null){
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(ps != null){
try {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(co != null){
try {
co.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
执行语句
package com.jdbc.tools;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
/**
* Author : YWJ
* Date : 2023/3/5
* 执行sql工具
*/
public class ExecuteSQLTool {
//增 -- 删 -- 改
public static int executeUpdate(String sql ,Object...args){
Connection co = null ;
PreparedStatement ps = null ;
int column = 0 ;
try {
co = GetJdbcConnectionTool.getJdbcConnect();
ps = co.prepareStatement(sql);
for (int i = 0; i < args.length; i++) {
ps.setObject(i+1,args[i]);
}
column = ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally {
ResourcesCloseTool.closeResources(co,ps,null);
}
return column;
}
//查 -- 利用反射
public static <E>E executeSelectOne(Class<E> clazz,String sql ,Object ...args){
Connection co = null ;
PreparedStatement ps = null ;
ResultSet rs = null ;
E re = null ;
try {
re = clazz.getConstructor().newInstance();
co = GetJdbcConnectionTool.getJdbcConnect();
ps = co.prepareStatement(sql);
for (int i = 0; i < args.length; i++) {
ps.setObject(i+1,args[i]);
}
rs = ps.executeQuery();
ResultSetMetaData metaData = null ;
if(rs.next()){
metaData = rs.getMetaData();
int columnCount = metaData.getColumnCount();
for (int i = 1; i <= columnCount; i++) {
String columnLabel = metaData.getColumnLabel(i);// 获取别名
Object columnValue= rs.getObject(columnLabel);// 获取属性值
Field field = clazz.getDeclaredField(columnLabel);
field.setAccessible(true);
field.set(re,columnValue);
}
}
} catch (SQLException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchFieldException e) {
e.printStackTrace();
}finally {
ResourcesCloseTool.closeResources(co,ps,rs);
}
return re;
}
// 查多个
public static <E>List<E> executeSelectAll(Class<E> clazz,String sql ,Object ...args){
List<E> list = new ArrayList<>();
Connection co = null ;
PreparedStatement ps = null ;
ResultSet rs = null ;
try {
co = GetJdbcConnectionTool.getJdbcConnect();
ps = co.prepareStatement(sql);
for (int i = 0; i < args.length; i++) {
ps.setObject(i+1,args[i]);
}
rs = ps.executeQuery();
ResultSetMetaData metaData = null ;
E re = null ;
while (rs.next()){
re = clazz.getConstructor().newInstance();
metaData = rs.getMetaData();
int columnCount = metaData.getColumnCount();
for (int i = 1; i <= columnCount; i++) {
String columnLabel = metaData.getColumnLabel(i);// 获取别名
Object columnValue= rs.getObject(columnLabel);// 获取属性值
Field field = clazz.getDeclaredField(columnLabel);
field.setAccessible(true);
field.set(re,columnValue);
}
list.add(re) ;
}
} catch (SQLException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchFieldException e) {
e.printStackTrace();
}finally {
ResourcesCloseTool.closeResources(co,ps,rs);
}
return list;
}
}
测试文件
import com.jdbc.tools.ExecuteSQLTool;
import org.junit.jupiter.api.Test;
import java.util.List;
/**
* Author : YWJ
* Date : 2023/3/5
*/
public class ToolsTest {
@Test
void testInsert(){
String sql1 = "insert into `student` " +
"(`name`,`pwd`,`sex`,`birthday`,`address`,`email`) " +
"values (?,'020517','男','2002-05-17 12:00:00',?,'[email protected]')"; // 增
String sql2 = "delete from student where name= ?" ; // 删
String sql3 = "update student set name = ? where name= ?"; // 改
int column = ExecuteSQLTool.executeUpdate(sql3, "张三","王刚");
if(column>0) {
System.out.println("successful !");
}
}
@Test
void testSelectOne(){
String sql = "select id id , name name , pwd,pwd,sex sex,birthday,birthday,address address,email,email " +
"from student where name = ?";
Student student = ExecuteSQLTool.executeSelectOne(Student.class,sql,"张三");
}
@Test
void testSelectAll(){
String sql = "select id id , name name , pwd,pwd,sex sex,birthday,birthday,address address,email,email " +
"from student ";
List<Student> list = ExecuteSQLTool.executeSelectAll(Student.class, sql);
System.out.println(list);
}
}