zoukankan      html  css  js  c++  java
  • 测试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();
                }
            }    
  • 相关阅读:
    【SPOJ1825】Free Tour II-点分治+桶排序
    【BZOJ3238】差异(AHOI2013)-后缀自动机+树形DP
    Vacation
    Function
    Path
    杭电oj初体验之 Code
    挑7
    行游散记!
    坐标移动
    STL之pair类型
  • 原文地址:https://www.cnblogs.com/xiaoqiqistudy/p/11177985.html
Copyright © 2011-2022 走看看