shz.jdbc.generate.DefaultGenerator Maven / Gradle / Ivy
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);
}
}
}