Tuesday, 15 April 2014

java - JDBC - Connection extremely slow on Windows, Fine on Linux -


By using JDBC to connect to SQL Server on a Windows Server 2008 computer, I ran into an extremely confusing problem

Using Microsoft's JDBC driver and JTDS, it works very well on my Linux laptop, but when executing the application on a device running Windows, then executing a single SQL command It takes 4 to 10 seconds!

I have tried to connect all of the following technologies to the database server, almost all Linux is fast and very slow on Windows, using the JTD data source, I have learned that it is on Windows 8 Works fine, but when I go to a computer on a computer (Windows Server), it always slows down the code.

  // = ============== jTDS JtdsDataSource DS = New JtdsDataSource (); Ds.setUser (DB_USERNAME); Ds.setPassword (DB_PASSWORD); Ds.setServerName (SERVER_ADDRESS); Ds.setPortNumber (SERVER_PORT); Ds.setDatabaseName (Database_Name); Ds.setLoginTimeout (server.SQL_LOGIN_TIMEOUT); Try {_Conn_ = ds.getConnection (); } Hold (SQLException e) {e.printstaxtrace (); return false; } // ============== Try Microsoft {string connectionRuril = string.format ("jdbc: sqlserver: //% s:% d;" + "database name =% s ; "+" Ssl = require ", SERVER_ADDRESS, SERVER_PORT, DATABASE_NAME); Class.forName ("com.microsoft.sqlserver.jdbc.SQLServerDriver"); This._conn_ = DriverManager.getConnection (connectionUrl, DB_USERNAME, DB_PASSWORD); } Grip (Klassnotfound Expression E) {e.printStackTrace (); Throw New Runtime Exception ("JDBC Not Loaded"); } Hold (SQLException e) {e.printstaxtrace (); return false; } // =============== Apache string connection = "jdbc: sqlserver: //" + SERVER_ADDRESS + "; database =" + DATABASE_NAME + "; integrated security = false;"; String jtdsConnectionUrl = "jdbc: jtds: sqlserver: //" + SERVER_ADDRESS + ":" + SERVER_PORT + "/" + DATABASE_NAME + ""; Connectionfactory connectionfactor = new driver managerconnectfactor (jtdsConnectionUrl, DB_USERNAME, DB_PASSWORD); Poolable Connectivity Fittering Console Connection Factor = New PoolBal Connection Fitterator (Connection Faner, Empty); PoolableConnectionFactory.setDefaultAutoCommit (true); PoolableConnectionFactory.setDefaultReadOnly (incorrect); GenericObjectPool connectionpool = new GenericObjectPool (poolableConnectionFactory); PoolableConnectionFactory.setPool (connectionPool); This.pooledDataSource = New PoolingDataSource (connectionPool);  

It's already a week, I'm stuck on it, any help is appreciated.

Good, this is not really the right solution, but works a few hours after working on it And after almost everything (writing a custom connection pool to use Apache DBC), I came to know that the problem begins, after a TCP connection to my server

I realized that Do I reconnect with each connection made from server to SQL database Class I, too slow behavior just does not happen so fast, this is a transaction which is almost that takes 50 seconds instead of 5 seconds is good enough.

I do not even know why this happens and my condition is in the Windows Server or VMWire network bug because this behavior changes by changing the platform. I hope it helps if someone else is facing the same problem.


No comments:

Post a Comment