zoukankan      html  css  js  c++  java
  • JDBCTool

    新建 *.properties属性文件,内容如下:

    driver=com.mysql.jdbc.Driver

    url=jdbc:mysql://localhost:3306/dbName

    username=root

    password=root

    public class DbTool {
    private static String db_driver=null;
    private static String db_url=null;
    private static String db_user=null;
    private static String db_password=null;
    public static Connection getConnection() throws ClassNotFoundException, IOException{
    Connection conn=null;
    InputStream in=DbTool.class.getClassLoader().getResourceAsStream("jdbc.properties");
    Properties properties=new Properties();
    properties.load(in);
    db_driver=properties.getProperty("driver");
    db_url=properties.getProperty("url");
    db_user=properties.getProperty("user");
    db_password=properties.getProperty("password");
    try {
    Class.forName(db_driver);
    conn=DriverManager.getConnection(db_url,db_user,db_password);
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    // TODO Auto-generated catch block
    // TODO Auto-generated catch block
    return conn;
    }

    public static void close(ResultSet rs){
    if(rs!=null){
    try {
    rs.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }
    public static void close(PreparedStatement prst){
    if(prst!=null){
    try {
    prst.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }
    public static void close(Connection conn){
    if(conn!=null){
    try {
    conn.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }
    public static void close(PreparedStatement prst,Connection conn){
    close(prst);
    close(conn);
    }
    public static void close(ResultSet rs,PreparedStatement prst,Connection conn){

    close(rs);
    close(prst);
    close(conn);



    }

    }

  • 相关阅读:
    十层框架
    大规模web服务开发技术
    ASP.NET三层架构基础详细操作图文教程
    ASP.NET MVC4中的异步控制器
    集成多个子系统的单点登录(网站入口方式)附源码
    我的C#全能Excel操作(无需Office,不使用XML)
    代码重构——程序员应有的基因
    通过监听Windows消息对复合控件进行整体控制
    Android游戏框架
    Ext.NET
  • 原文地址:https://www.cnblogs.com/cn-chy-com/p/7467488.html
Copyright © 2011-2022 走看看