oracle,sqlserver,mysql常见数据库jdbc连接

发现JDBC连接字符串总是容易忘记,特此整理一下常用的几种数据的连接

ORACLE

  /**
     * ORACLE
     * */
    public static Connection getOracleConnection(){
        Connection connection = null;
        try {
            Class.forName("oracle.jdbc.OracleDriver");
            connection = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl", "username", "password");
        } catch (Exception e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
        return connection;
    }

SQLSERVER

    /**
     * SQLSERVER
     * */
    public static Connection getSqlServerConnection(){
        Connection connection = null;
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            connection = DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test", "username", "password");
        } catch (Exception e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
        return connection;
    }

MYSQL

    /**
     * MYSQL
     * */
    public static Connection getMySqlConnection(){
        Connection connection = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test", "username", "password");
        } catch (Exception e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
        return connection;
    }
原文地址:https://www.cnblogs.com/gavinYang/p/3515890.html