JDBC连接挂起,SQL Server 2008 r2没有响应 [英] JDBC connection hangs with no response from SQL Server 2008 r2

查看:145
本文介绍了JDBC连接挂起,SQL Server 2008 r2没有响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当连接到SQL Server 2008(在本地表达,在生产中使用完整服务器)时,在我的本地计算机上进行开发时,这对我来说很好,但这件事只是在生产中挂起。

When connecting to SQL Server 2008 (express locally, full server in production) this works fine for me when developing on my local machine, but this thing just hangs in production.

以下是代码:

package oata;

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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import sun.applet.Main;

public class Sql {

    public static final String SQLDRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
    protected Connection conn = null;
    private String ip = "";
    private int port = 0;
    private String databaseName = "";
    private String db_userid = "";
    private String db_password = "";

    public void callDb(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException{
        System.out.println("Initialising variables");
        ip = args[0];
        port =  Integer.parseInt(args[1]);
        databaseName = args[2];
        db_userid = args[3];
        db_password = args[4];
        try{
        Log logger = LogFactory.getLog(Main.class);
        System.out.println("Opening logger...");
        logger.debug("opening driver " + SQLDRIVER);
        System.out.println("Creating connection instance...");
        Class.forName(SQLDRIVER).newInstance();
        System.out.println("Driver Manager.getConnection...");
        conn = DriverManager.getConnection(getDBURL(), db_userid, db_password);
        System.out.println("Connection prepare statement...");
        PreparedStatement ps = conn.prepareStatement("select * from nstupersonal");
        System.out.println("Executing query...");
        ResultSet rs = ps.executeQuery();
        while(rs.next()){
            System.out.println(rs.getString("StudentId"));
        }
        }catch(Exception e){
            System.out.println(e.getMessage());
        }

        conn.close();
    }


    private String getDBURL(){
                String url = "";
                try {
                    url = "jdbc:sqlserver://" + ip
                    +":" + port +";databaseName="+
                     databaseName + ";user=" + db_userid + ";password="+db_password;
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }   
                return url;
            } 

}

这是运行的代码。在控制台中,它实际上只是在生产中挂起。它似乎总是挂在SQL Server 2008上,但在我的所有其他客户的生产中运行良好。与......一起运行

That's the code that gets run. In the console it literally just hangs in production. It always seems to hang on SQL server 2008 but works fine in production for all my other customers. Runs simiply with...

在SQL Server中的1433上启用TCP / IP,并允许在管理控制台中将远程连接设置为true。

TCP/IP is enabled on 1433 in SQL Server and allow remote connections is set to true in the management console.

java -jar ipaddress port dbname用户密码

java -jar ipaddress port dbname user password

有什么想法吗? SQL驱动程序错了吗?我正在使用sqljdbc4.jar

Any ideas? Is the SQL driver wrong? I'm using sqljdbc4.jar

结果命令提示符为...

The resulting command prompt is...

初始化变量
打开记录器...
Driver Manager.getConnection ...

Initialising variables Opening logger... Driver Manager.getConnection...

不抛出任何异常

谢谢,

D

推荐答案

如果生产正在Java上运行6更新29,然后升级到Java 6 Update 30或降级到Java 6 update 27(?)。更新29包含错误,其中SSL无法正常工作和连接到SQL Server挂起。

If production is running on Java 6 Update 29, then either upgrade to Java 6 Update 30 or downgrade to Java 6 update 27(?). Update 29 contains a bug where SSL doesn't work correctly and the connection to SQL Server hangs.

这篇关于JDBC连接挂起,SQL Server 2008 r2没有响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆