首页>代码>java简单封装JDBC通过properties文件读取配置,连接和操作数据库>/JavaJDBCPackage/src/com/zhel/jdbc1/main/JdbcUtilsMain.java
package com.zhel.jdbc1.main; import java.util.LinkedList; import java.util.List; import com.zhel.jdbc1.entity.Departments; import com.zhel.jdbc1.jdbcUtil.JdbcUtilsService; public class JdbcUtilsMain { public static void main(String[] args) { JdbcUtilsService jdbcUtilsService = new JdbcUtilsService(); String sql = "insert into departments (dept_name) values (?)"; List<Object> params = new LinkedList<>(); params.add("后勤部"); jdbcUtilsService.update(sql, params); String sql1 = "select dept_name from departments where id = ?"; List<Object> params1 = new LinkedList<>(); params1.add(2); Departments departments = jdbcUtilsService.querySimpleRef(sql1, params1, Departments.class); System.out.println(departments); jdbcUtilsService.close(); // 最后记得关闭服务 } }