yinusxxxx

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
package utils;

import java.sql.*;

/**
 * Created by yinus on 2016/4/4.
 */

public class Dbtuil {
    private static final String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
    private static final String dbURL="jdbc:sqlserver://localhost:port;DatabaseName=tableName";
    private static final String userName="usrName";
    private static final String userPwd="password";
    private static Connection connection = null;
    static{
        try {
            Class.forName(driverName);
            connection=DriverManager.getConnection(dbURL,userName,userPwd);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    public static Connection getConnection(){
        return connection;
    }

    public static void close() throws SQLException {
        connection.close();
    }
}

 

posted on 2016-04-10 15:20  yinusxxxx  阅读(241)  评论(0编辑  收藏  举报