com.auto.common.utils.db.mysql.MySQLDBUtils Maven / Gradle / Ivy
package com.auto.common.utils.db.mysql;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MySQLDBUtils {
private static Logger logger = LoggerFactory.getLogger(MySQLDBUtils.class);
private MySQLDBUtils() {
//do nothing
}
/**
* This method is used to create connection
*
* @return
*/
public static Connection connection(final String dbHost, final String userName, final String password,
final String dbDriver) {
Connection conn = null;
try {
Class.forName(dbDriver);
conn = DriverManager.getConnection(dbHost, userName, password);
} catch (Exception error) {
error.printStackTrace();
}
return conn;
}
/**
* This method is used to execute db query for select command
*
* @param query
* @param conn
* @return
* @throws SQLException
*/
public static List