码迷,mamicode.com
首页 > 数据库 > 详细

DbConnectionFactory 数据库连接

时间:2016-12-30 16:54:21      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:import   失败   pass   ctf   ons   this   bst   name   try   

/**
*
*/
package com.sprucetec.dbatch.tmsfee;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import scala.runtime.AbstractFunction0;


public class DbConnectionFactory {

static AbstractFunction0<Connection> getTmsBasic(){
return new AbstractFunction0Seri(Constants.Url4TmsBasic, Constants.User4TmsBasic, Constants.Pass4TmsBasic);
}

static AbstractFunction0<Connection> getTms(){
return new AbstractFunction0Seri(Constants.Url4Tms, Constants.User4Tms, Constants.Pass4Tms);
}

static AbstractFunction0<Connection> getTmsDC(){
return new AbstractFunction0Seri(Constants.Url4TmsDC, Constants.User4TmsDC, Constants.Pass4TmsDC);
}

private static class AbstractFunction0Seri extends AbstractFunction0<Connection> implements Serializable{

private static final long serialVersionUID = 1L;

private final String url;

private final String username;

private final String password;

public AbstractFunction0Seri(String url,String username,String password){
this.url = url;
this.username = username;
this.password = password;
}

@Override
public Connection apply() {
try {
return DriverManager.getConnection(this.url, this.username, this.password);
} catch (SQLException e) {
throw new RuntimeException("数据库连接失败", e);
}
}
}

}

DbConnectionFactory 数据库连接

标签:import   失败   pass   ctf   ons   this   bst   name   try   

原文地址:http://www.cnblogs.com/duyinqiang/p/6237226.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!