• 测试JDBC


        A:加载驱动
            1:将相关数据库的驱动包拷到对应的应用程序中。并加载到编译路径中。

            2:使用Class.forName来加载相应的驱动程序。

        B:使用驱动管理器获取连接
            String url = "
    jdbc:mysql://localhost:3306/jdbcstudy";
            String username = "root";
            String password = "123456";
            Connection conn = DriverManager.getConnection(url, username,
                    password);        

        C:构造SQL,并通过Statement对象执行SQL
            Statement stmt = conn.createStatement();
            System.out.println(stmt);
            String sql = "insert into t_mc_type(nid,sname,npid) values(15,'JDBC插入的数据','1')";
            int i = stmt.executeUpdate(sql);        
        D:关闭资源
            finally {
                try {
                    if (stmt != null) {
                        stmt.close();
                    }
                    if (conn != null) {
                        conn.close();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }    
  • 相关阅读:
    排查线上问题常用的几个Linux命令
    OAuth2简易实战(一)-四种模式
    程序员必备的网站推荐
    C++ sizeof
    C++ 求余运算符
    C++ mutable(可变的)
    C++ const_cast用法
    C++常变量和文字常量
    C++中 <iso646.h>头文件
    java-网络编程-使用URLDecoder和URLEncoder
  • 原文地址:https://www.cnblogs.com/xiaoqiqistudy/p/11177985.html
Copyright © 2020-2023  润新知