Java Utililty Methods JDBC MySQL Connection

List of utility methods to do JDBC MySQL Connection

Description

The list of methods to do JDBC MySQL Connection are organized into topic(s).

Method

ConnectiongetMySQLConnection(String hostname, String databaseName, String dbuser, String dbpasswort)
Gets the my sql connection.
return getMySQLConnection(hostname, MYSQL_PORT, databaseName, dbuser, dbpasswort);
ConnectiongetMySQLConnection(String hostName, String dbName, String userName, String password)
get My SQL Connection
Class.forName("com.mysql.jdbc.Driver");
String connectionURL = "jdbc:mysql://localhost:3306/test1";
Connection conn = DriverManager.getConnection(connectionURL, userName, password);
return conn;
HashMap>getMysqlIndices(String conString)
get Mysql Indices
HashMap<String, HashSet<String>> result = new HashMap<String, HashSet<String>>();
Connection conn;
conn = DriverManager.getConnection(conString);
DatabaseMetaData meta = conn.getMetaData();
ResultSet tables = meta.getTables(null, null, null, null);
while (tables.next()) {
    ResultSet rs;
    String tableName = tables.getString(3);
...
ConnectiongetNewDatabaseConnection(String dbUser, String dbPassword)
get New Database Connection
lookupDriver();
return connectAndUseDatabase(dbUser, dbPassword);
ConnectiongetRssminerDB()
get Rssminer DB
Connection con = DriverManager.getConnection(JDBC_URL, "feng", "");
return con;
ConnectiongetSearchReaderConnection()
get Search Reader Connection
if (searchReaderConnection == null || searchReaderConnection.isClosed()) {
    searchReaderConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/ycppquiz", "ycppquiz",
            "ycppquiz");
return searchReaderConnection;
voidopenConnection()
open Connection
try {
    Class.forName("com.mysql.jdbc.Driver");
    mConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/source_products", "root", "123");
    mStmt = mConn.createStatement();
} catch (Exception e) {
    e.printStackTrace();
voidputData(int tID, String toolID)
put Data
Connection con = null;
PreparedStatement preparedStatement = null;
try {
    Class.forName("com.mysql.jdbc.Driver");
    con = DriverManager.getConnection(dbUrl, user, password);
    preparedStatement = con.prepareStatement(addDataQ);
    preparedStatement.setInt(1, tID);
    preparedStatement.setString(2, toolID);
...
ResultSetquery(String sql)
query
try {
    if (mStmt == null || mStmt.isClosed()) {
        openConnection();
    return mStmt.executeQuery(sql);
} catch (SQLException e) {
    e.printStackTrace();
return null;
List>queryAll(String sql, List params)
query All
List<List<Object>> result = new ArrayList<List<Object>>();
Connection connection = null;
try {
    connection = DriverManager.getConnection(url, user, password);
    PreparedStatement ps = connection.prepareStatement(sql);
    if (params != null && params.size() > 0) {
        for (int i = 0; i < params.size(); i++) {
            ps.setObject(i + 1, params.get(i));
...