DbConnectionFactory 数据库连接
Posted 程序媛的故事
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 数据库连接的主要内容,如果未能解决你的问题,请参考以下文章