/** * */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); } } } }
时间: 2024-10-12 18:56:02