软件3班20240513






java.util.PropertyResourceBundle@4554617c






java 复制代码
package com.yanyu;

import java.sql.*;
import java.util.ResourceBundle;

public class JDBCTest01 {
    public static void main(String[] args) throws SQLException {
//        获取属性配置文件
        ResourceBundle bundle = ResourceBundle.getBundle("com/yanyu/db");//ctrl   alt   v
//        System.out.println(bundle);//   CTRL  SHIFT   F10  java.util.PropertyResourceBundle@4554617c
        String driver = bundle.getString("driver");

        String url = bundle.getString("url");
        String user = bundle.getString("user");
        String password = bundle.getString("password");
//
        Connection con = null;
        Statement st = null;
        ResultSet rs = null;

//        注册驱动
        try {
            Class.forName(driver);//  alt   enter
            con = DriverManager.getConnection(url, user, password);
//            System.out.println(connection);
            con.setAutoCommit(false);
            st = con.createStatement();
//            关闭十五自动提交
            String sql = "insert into t_user values(2,'yanyu2')";
            boolean execute = st.execute(sql);
//            System.out.println(execute?"数据插入成功":"数据插入失败");


            con.commit();
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (SQLException e) {
            if (con != null) {
                con.rollback();
            }
            throw new RuntimeException(e);
        } finally {
            if (rs != null) {
                rs.close();
            }
            if (st != null) {
                st.close();
            }
            if (con != null) {
                con.close();
            }
        }
//        异常     方法未重写(继承 父类   接口)



    }
}
java 复制代码
driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/soft03
#https:www.baidu.com
user=root
password=root
相关推荐
冷雨夜中漫步7 小时前
Python快速入门(6)——for/if/while语句
开发语言·经验分享·笔记·python
JH30738 小时前
SpringBoot 优雅处理金额格式化:拦截器+自定义注解方案
java·spring boot·spring
m0_736919109 小时前
C++代码风格检查工具
开发语言·c++·算法
Coder_Boy_9 小时前
技术让开发更轻松的底层矛盾
java·大数据·数据库·人工智能·深度学习
2501_944934739 小时前
高职大数据技术专业,CDA和Python认证优先考哪个?
大数据·开发语言·python
invicinble10 小时前
对tomcat的提供的功能与底层拓扑结构与实现机制的理解
java·tomcat
较真的菜鸟10 小时前
使用ASM和agent监控属性变化
java
黎雁·泠崖10 小时前
【魔法森林冒险】5/14 Allen类(三):任务进度与状态管理
java·开发语言
2301_7634724611 小时前
C++20概念(Concepts)入门指南
开发语言·c++·算法
TechWJ11 小时前
PyPTO编程范式深度解读:让NPU开发像写Python一样简单
开发语言·python·cann·pypto