当前位置:首页 > 数据库 > Oracle

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;
    }

原文:http://www.cnblogs.com/gavinYang/p/3515890.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐