Sha256: 0290c0aa53eb432b52298d10170d77aeb290f81d1667beed6f484487bca271cf

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 KB

Contents

package org.embulk.filter.mysql_lookup;

import java.sql.Connection;
import java.sql.DriverManager;

public class DatabaseConnection {
    private static Connection connection=null;

    private DatabaseConnection(MysqlLookupFilterPlugin.PluginTask task) throws Exception {
        try{
            Class.forName("com.mysql.cj.jdbc.Driver");
            String url = "jdbc:mysql://" + task.getHost() + ":"+task.getPort()+"/"+task.getDatabase();
            connection= DriverManager.getConnection(url, task.getUserName(), task.getPassword());
        }catch (Exception e){
            e.printStackTrace();
            throw new Exception(e);
        }

    }

    public static Connection getConnection(MysqlLookupFilterPlugin.PluginTask task){
        try {
            if(connection==null || connection.isClosed()){
                try {
                    new DatabaseConnection(task);
                    return connection;
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new RuntimeException();
                }
            }
        }catch (Exception e){
            throw new RuntimeException(e);
        }

        return connection;
    }
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
embulk-filter-mysql_lookup-0.1.4 src/main/java/org/embulk/filter/mysql_lookup/DatabaseConnection.java
embulk-filter-mysql_lookup-0.1.3 src/main/java/org/embulk/filter/mysql_lookup/DatabaseConnection.java
embulk-filter-mysql_lookup-0.1.2 src/main/java/org/embulk/filter/mysql_lookup/DatabaseConnection.java
embulk-filter-mysql_lookup-0.1.1 src/main/java/org/embulk/filter/mysql_lookup/DatabaseConnection.java