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 数据库连接的主要内容,如果未能解决你的问题,请参考以下文章

Tomcat 池不重置池。获得太多连接错误

一个基于注解的orm简单实现:实现思路

数据库的内连接外连接(左外连接右外连接全外连接)以及交叉连接(转)

java数据库连接池最大连接数最小连接数怎么设置

java数据库连接池最大连接数最小连接数怎么设置

mysql数据库——连接查询(内连接:自然连接,等值连接。外连接:左连接,右连接,全连接)