随笔分类 -  JDBC

摘要:1.在实现增删改查时,首先应先声明一个成员变量,QueryRunner类型的成员变量,注意不要使用无参构造方法,要将连接池的对象传入其中。 private QueryRunner queryRunner = new QueryRunner(DButil.getDruidDataSource()); 阅读全文
posted @ 2021-11-19 17:10 软工小蜗牛 阅读(381) 评论(0) 推荐(0)
摘要:1.首先声明一个连接池对象 private static DruidDateSource druidDateSource; 2.在获得字节流之后,在获取连接池的值 通过DruidDateSourceFactory.createDateSource方法获得 此方法接收的为一个properties集合, 阅读全文
posted @ 2021-11-10 09:26 软工小蜗牛 阅读(125) 评论(0) 推荐(0)
摘要:1.首先先写配置文件 配置文件包括 driver 驱动 url user password 四部分 2.在工具类中首先声明一个静态常量 private static final Properties properties = new Properties();//存储配置文件的map集合; 3.获得 阅读全文
posted @ 2021-11-10 08:38 软工小蜗牛 阅读(143) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2021-11-02 20:32 软工小蜗牛 阅读(78) 评论(0) 推荐(0)
摘要:1.实体类(entity):零散数据的载体 也就是说,你的表的名字是什么,就将类定义成什么名字,表中的每一列都定义一个私有变量,然后将每个变量设置get set 方法 在遍历的时候,将创建的类添加到一个集合里 阅读全文
posted @ 2021-11-02 19:21 软工小蜗牛 阅读(134) 评论(0) 推荐(0)
摘要:将连接数据库的方法进行封装,并在别的类中进行使用,并且要声明静态方法, //1.获取连接 public static Connection getConnection() { Connection connection = null; try { Class.forName("com.mysql.j 阅读全文
posted @ 2021-11-02 17:03 软工小蜗牛 阅读(254) 评论(0) 推荐(0)
摘要:创建PreparedStatement对象 PreparedStatement preparedStatement = connection.PreparedStatement(sql语句); 此时sql语句必须写好,不能通过一个变量再进行传入,因为PreparedStatement要做预编译 Pr 阅读全文
posted @ 2021-11-01 20:14 软工小蜗牛 阅读(399) 评论(0) 推荐(0)
摘要:1.首先,要注册驱动 Class.forName("com.mysql.jdbc.Driver"); 2.连接数据库 String url = "jdbc:mysql://localhost:3306:数据库名称";//?&useUnicode=true&serverTimezone=UTC加这句话 阅读全文
posted @ 2021-11-01 19:02 软工小蜗牛 阅读(606) 评论(0) 推荐(0)