首页 > 代码库 > DbConnectionFactory 数据库连接
DbConnectionFactory 数据库连接
/**
*
*/
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 数据库连接
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。