求助RDSSQLServer2008JAVADBCP连接池问题-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

求助RDSSQLServer2008JAVADBCP连接池问题

icepoint 2015-08-13 15:32:55 8745
应用中使用DBCP连接池,线下环境部署运行正常,但迁移到云上后就抛连接获取错误。
于是写了个测试

        String JDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
        String dbURL = "jdbc:sqlserver://jxajyhxt.sqlserver.rds.aliyuncs.com:3433;databasename=jxaj1";
        String userName = "**"; // 用户名
        String userPwd = "******"; // 密码


        ArrayList<Connection> dbConns = new ArrayList<Connection>();;
        try {
            Class.forName(JDriver).newInstance();
            for (int i = 0; i < 10; i++){
                System.out.print ("获取连接 ["+i+"]");
                Connection dbConn = DriverManager.getConnection (dbURL, userName, userPwd);
                System.out.println(dbConn.getMetaData().getURL());
                dbConns.add(dbConn);
            }
        } catch (Exception e) {
            e.printStackTrace ();
        } finally {
            try {
                for (int i = 0, len = dbConns.size (); i < len; i++){
                    System.out.println ("释放连接 ["+i+"]");
                    Connection dbConn = dbConns.get(i);
                    if (dbConn != null) dbConn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace ();
            }
        }
每次都是能获取到一个连接,但在取第二个连接时报错
------------------------------------------------------------------------------------------------------------------------

获取连接 [0] jdbc:sqlserver://jxajyhxt.sqlserver.rds.aliyuncs.com:3433;responseBuffering=adaptive;encrypt=false;databaseName=jxaj1;selectMethod=direct;trustServerCertificate=false;applicationName=Microsoft SQL Server JDBC Driver;lastUpdateCount=true;
获取连接 [1] com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the host R8IC01361, named instance MS3022 has failed. Error: java.net.UnknownHostException: R8IC01361. Please verify the server and instance names, check that no firewall is blocking UDP traffic to port 1434, and for SQL Server 2005 or later, verify that the SQL Server Browser service is running on the host.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:130)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.getInstancePort(SQLServerConnection.java:3090)
    at com.microsoft.sqlserver.jdbc.FailoverInfo.setupInfo(FailOverInfo.java:59)
    at com.microsoft.sqlserver.jdbc.FailoverInfo.failoverPermissionCheck(FailOverInfo.java:85)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithFailover(SQLServerConnection.java:812)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:763)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:842)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at com.topinfo.jxaj.test.DbTest.getConnectionSqlServer(DbTest.java:28)
    at com.topinfo.jxaj.test.DbTest.main(DbTest.java:64)
释放连接 [0]
------------------------------------------------------------------------------------------------
跟连接池报的错误一致。解析出的host: R8IC01361  是机器名还是....


谁能帮助一下,万分感谢!



SQL Java 数据库连接 数据安全/隐私保护
分享到
取消 提交回答
全部回答(2)
  • 石沫
    2015-08-18 11:30:49
    这个是JDBC驱动的问题,已经有很多用户遇到过,你换一下驱动就好了。
    0 0
  • 小柒2012
    2015-08-14 20:06:45
    楼主Java项目中配置的连接池大小是多少?
    0 0
添加回答
数据库
使用钉钉扫一扫加入圈子
+ 订阅

分享数据库前沿,解构实战干货,推动数据库技术变革

推荐文章
相似问题
推荐课程