zoukankan      html  css  js  c++  java
  • 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);
    }
    }
    }

    }
  • 相关阅读:
    2020-03-1811:29:37springboot与任务
    2020-03-17 20:18:50springboot整合rabbitmq
    2020.03.17 springboot缓存相关
    前端JS面试
    npm 常用指令
    ES8新特性
    ES7新特性
    ES6新特性
    SpringBoot
    SpringBoot
  • 原文地址:https://www.cnblogs.com/duyinqiang/p/6237226.html
Copyright © 2011-2022 走看看