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();
                }
            }    
  • 相关阅读:
    sql server与c#中数据类型的对应关系
    XML操作类
    手機錄音amr格式轉換工具
    ajax get,post提交數據
    javascript對文本encode編碼
    桌面图标透明设置→详解
    货币大写转换类
    利用DataAdapter於數擾庫同步
    JavaScript的RegExp对象
    添加計劃任務,自動備份腳本
  • 原文地址:https://www.cnblogs.com/xiaoqiqistudy/p/11177985.html
Copyright © 2011-2022 走看看