JDBC connection hangs unanswered SQL Server 2008 r2

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

Here is the code:

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

This code runs. In the console, it literally just hangs in production. It seems like it always relies on SQL Server 2008, but works great in production for all my other clients. It works similarly with ...

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

java -jar ipaddress port username dbname

Any ideas? Is the SQL driver incorrect? I am using sqljdbc4.jar

Received team invitation ...

Initializing Variables Opening Registrar ... Driver Manager.getConnection ...

No exception is thrown

Thanks,

D

+4
source share
3 answers

If the production runs on Java 6 Update 29, then either upgrade to version 6 6, or upgrade to Java 6 update 27 (?). Update 29 contains an error where SSL is not working properly and the connection to SQL Server freezes.

+11
source

You can take a snapshot of the thread stack trace and see where it got stuck. If reading it on a socket is something wrong in db (I think it will be here).

+1
source

I encountered the same behavior with the MS SQL Server 2012 + JDBC 4.0 driver, and again the JDK 6.0 29 problem was a problem. The connection was suspended on the first call to executeQuery () or even with setAutoCommit (false) before any query was issued. After upgrading to JDK 6.0, everything works fine.

NTN, Michal

+1
source

Source: https://habr.com/ru/post/1392667/


All Articles