All Downloads are FREE. Search and download functionalities are using the official Maven repository.

shz.jdbc.generate.DefaultGenerator Maven / Gradle / Ivy

There is a newer version: 2024.0.1
Show newest version
package shz.jdbc.generate;

import shz.core.PRException;
import shz.core.cl.ClassLoaderHelp;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public abstract class DefaultGenerator extends Generator {
    protected final Properties properties;

    protected DefaultGenerator(Properties properties) {
        this.properties = properties;
    }

    protected DefaultGenerator(String driverClassName, String url, String user, String password) {
        properties = new Properties();
        properties.put("driverClassName", driverClassName);
        properties.put("url", url);
        properties.put("user", user);
        properties.put("password", password);
    }

    @Override
    protected Connection conn() {
        Properties prop = new Properties();
        prop.putAll(properties);

        prop.put("useInformationSchema", "true");
        prop.put("remarksReporting", "true");

        String url = prop.getProperty("url");
        try {
            return DriverManager.getConnection(url, prop);
        } catch (SQLException e) {
            ClassLoaderHelp.load(prop.getProperty("driverClassName"));
        }

        try {
            return DriverManager.getConnection(url, prop);
        } catch (SQLException e) {
            throw PRException.of(e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy