0

I am trying to connect my tomcat servers to a MS SQL 2008 R2 server. Network connectivity is not the issue here.

I can successfully connect in a simple java app, but when I try to connect via tomcat7 (tried on my Windows 7 workstation as well as my Ubuntu 12.04 server.

I am able to run the example servlets on both tomcat servers.

My code:

 public class DBConnector{`
 private java.sql.Connection  con = null;`
 private final String url = "jdbc:sqlserver://my.domain.com:";`

//PORT NUMBER, CREDENTIALS, ETC. These all work in standard java app.

public DBConnector(){}

private String getConnectionUrl(){
    return url+ portNumber +";databaseName="+databaseName+";selectMethod="+selectMethod+";";
}

private java.sql.Connection getConnection(){
     try{
          Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
          con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);
          if(con!=null) System.out.println(getConnectionUrl());
     }catch(Exception e){
          e.printStackTrace();
          System.out.println("Error Trace in getConnection() : " + e.getMessage());

    }
     return con;
 }


    public void queryDB(){

    try{
        System.out.println("Connecting...");
         con= this.getConnection();
         if(con!=null){
             System.out.println("NotNull");

            java.sql.Statement statement = con.createStatement();
            String query="Select * from CAFE";            
            java.sql.ResultSet rs = null;
            System.out.println("made rs");
            rs = statement.executeQuery(query);
            System.out.println("Established what it is");
            java.sql.ResultSetMetaData rsmd = rs.getMetaData();
            System.out.println("Getting MetaData");`
 //Omitted the rest.

It stops responding in tomcat at: rs = statement.executeQuery(query); because on the console, I never see "Established what it is".

I am using the correct mssql driver version for Java 6.

I am very new to this so quite likely made an obvious mistake here. Any suggestions?

NullPointer
  • 545
  • 1
  • 6
  • 17
  • 1
    What do you mean by stops responding? Does it sit there forever or does it actually throw an exception? If it throws and exception, what actual exception does it throw? – Remear Jul 06 '12 at 15:00
  • It just sits there forever, does not thrown an exception. – NullPointer Jul 06 '12 at 22:49
  • I believe I am experiencing this bug (I am using the exact same environnment). I will try updating to 1.6-30 from 1.6-29. – NullPointer Jul 07 '12 at 04:26

1 Answers1

0

Fixed it. Downgraded to:

java -version

java version "1.6.0_24"

Working properly now. Those who came here via search engine; refer to this: Driver.getConnection hangs using SQLServer driver and Java 1.6.0_29

Community
  • 1
  • 1
NullPointer
  • 545
  • 1
  • 6
  • 17