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

org.bdware.doip.audit.BasicDB Maven / Gradle / Ivy

There is a newer version: 1.5.4
Show newest version
package org.bdware.doip.audit;

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

public class BasicDB {
    //        ---------oracle------------
//        static String driverClass = "oracle.jdbc.driver.OracleDriver";
//        static String url="jdbc:oracle:thin:@39.101.64.229:1521:ORCLCDB";
//        static String user="c##user01";
//        static String password="123456";
//    ----------mysql------------
//        static String driverClass = "com.mysql.jdbc.Driver";
//        static String url="jdbc:mysql://39.101.64.229:3306/testDB";
//        static String user="root";
//        static String password="P@ssw0rd";
    public String driverClass;
    public String url;
    public String user;
    public String password;

    public BasicDB(String driverClass, String url, String user, String password) {
        this.driverClass = driverClass;
        this.url = url;
        this.user = user;
        this.password = password;
    }

    public Connection getConn() {
        Connection conn;
        try {
            Class.forName(driverClass);
            conn = DriverManager.getConnection(url, user, password);
            return conn;
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public String formatTableName(String tableName) {
        String formattedTableName;
        if (driverClass.contains("oracle")) {
            formattedTableName = "\"" + tableName + "\"";
        } else {
            formattedTableName = tableName;
        }
        return formattedTableName;
    }

    public String formatField(String field) {
        String formattedField;
        if (driverClass.contains("postgresql")) {
            formattedField = "'" + field + "'";
        } else {
            formattedField = field;
        }
        return formattedField;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy