I am trying to connect to a remote db2 database using the db2 jdbc drivers and am getting a sockertimeout error. I have deployed to two different machines and on the second machine I don't get the error. I'm thinking that this could be something to do with a network connection to the box that my db2 database is on.
Can anyone help me with ways that I can try and debug this error. So far the only think I can come up with is to use tracert hostname to compare the number of hops on the box that the connection works and on the one that it does not.
thanks
[11/5/14 14:22:46:537 EST] 0000d296 SystemErr R Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:413)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:274)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:261)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:389)
at java.net.Socket.connect(Socket.java:556)
at com.ibm.db2.jcc.a.y.run(y.java:34)
at java.security.AccessController.doPrivileged(AccessController.java:241)
at com.ibm.db2.jcc.a.xb.a(xb.java:390)
at com.ibm.db2.jcc.a.xb.<init>(xb.java:79)
at com.ibm.db2.jcc.a.a.x(a.java:265)
at com.ibm.db2.jcc.a.b.a(b.java:1781)
at com.ibm.db2.jcc.b.bb.a(bb.java:394)
at com.ibm.db2.jcc.b.bb.<init>(bb.java:354)
at com.ibm.db2.jcc.a.b.<init>(b.java:314)
at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:572)
at java.sql.DriverManager.getConnection(DriverManager.java:196)
at com.myer.epostools.db.DBUtility.createConnection(DBUtility.java:18)
at com.myer.eposweb.dao.BaseDAO.getConnection(BaseDAO.java:36)
Related
I have created a Postgres database on Azure via following the instructions from https://learn.microsoft.com/en-us/azure/postgresql/connect-java. Now I can connect to the database via my local PgAdmin and also from terminal with psql. However, when I try to connect with Hibernate (version 5.4.21) in my java code (java 8) I always get the following error without any explanations.
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:315)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:225)
at org.postgresql.Driver.makeConnection(Driver.java:465)
at org.postgresql.Driver.connect(Driver.java:264)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at test.ui.V9.main(V9.java:17)
Caused by: java.io.EOFException
at org.postgresql.core.PGStream.receiveChar(PGStream.java:443)
at org.postgresql.core.v3.ConnectionFactoryImpl.enableGSSEncrypted(ConnectionFactoryImpl.java:436)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:144)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:213)
... 7 more
I tried different SSL mode options but no success. I also disabled SSL from Azure side, but still no success. Can someone help me to resolve this issue?
We had the same issue with the 42.2.15 version of the driver.
Try to set
gssEncMode=disable
Read more: https://gitmemory.com/issue/pgjdbc/pgjdbc/1868/683710515
I have a web application running on JBoss 4.2.3 connecting to a SQL Server 2008 R2 database through JTDS 1.2.2 driver. The Datasource is setup to have minimum 10 connections in the pool. This is the ds file jtds-ds.xml: (I have replaced the real jndi name, server name, database name, user name and password).
<datasources>
<local-tx-datasource>
<jndi-name>MyDS</jndi-name>
<connection-url>jdbc:jtds:sqlserver://MyServer/MyDatabase;tds=8.0;lastupdatecount=true</connection-url>
<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
<user-name>MyUserName</user-name>
<password>MyPassword</password>
<set-tx-query-timeout>true</set-tx-query-timeout>
<!--
sql to call on an existing pooled connection when it is obtained from pool
-->
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
<!-- Pooling Parameters -->
<prepared-statement-cache-size>500</prepared-statement-cache-size>
<min-pool-size>10</min-pool-size>
<max-pool-size>40000</max-pool-size>
</local-tx-datasource>
</datasources>
I run the SQL Server Profiler. After the JBoss starts in the SQL Server Profiler, I can see 10 database connections to the MyDatabase database from the web application . Whenever any user works on the web application, I can see it in SQL Server Profiler. Everything looks good.
I start a process which is a very long process and insert million of rows in database. The process inserts 1000 rows at a time i.e. it gets connection from pool, insert 1000 rows in database, then close connection. I can see it in SQL Server Profiler and it is working ok.
While the process was running I got a warning in the log file and I think it was because the connection was lost to the database server
2015-03-26 11:50:35,611 WARN [org.jboss.resource.connectionmanager.JBossManagedConnectionPool] Unable to fill pool
org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.sql.SQLException: Network error IOException: Connection timed out: connect)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:190)
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPool.java:619)
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.fillToMin(InternalManagedConnectionPool.java:534)
at org.jboss.resource.connectionmanager.PoolFiller.run(PoolFiller.java:74)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.sql.SQLException: Network ` IOException: Connection timed out: connect
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:385)
at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:182)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:172)
... 4 more
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:304)
at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:255)
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:310)
... 7 more
After this error, the SQL Server Profiler is not showing any connections for the web application. JBoss is still running. Why JBoss would destroy its connection pool in this case?
UPDATE:
When another user's request comes in the web application, I saw the SQL Server Profiler shows me 4 connections by the web application. So it is at least start building the connection pool again although I would expect it to show 10 connections.
My question still is that when such an error occurs (Connection timed out), why JBoss drop the whole 10 connections in the connection pool? The process was using only 1 connection, the other 9 connections were not being used as there was nobody else using the web application when the process was run. Also is it possible for JBoss to rebuild its connection pool by itself when it was somehow destroyed? I thought check-valid-connection-sql tag does that trick?
I want to run a cyc (opencyc) Java class, but when I run this class I got an error mentioning that the network is unreachable. I am working on NetBeans 7.0 and opencyc 2.0 win 32 version. I am using localhost (127.0.0.1) to test. The error is below.
Network is unreachable: connect
java.net.SocketException: Network is unreachable: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:180)
at org.opencyc.api.CycConnection.initializeApiConnections(CycConnection.java:223)
at org.opencyc.api.CycConnection.<init>(CycConnection.java:199)
at org.opencyc.api.CycAccess.<init>(CycAccess.java:121)
at org.opencyc.api.CycAccess.<init>(CycAccess.java:61)
at org.opencyc.api.ApiDemo.<init>(ApiDemo.java:50)
at org.opencyc.api.ApiDemo.main(ApiDemo.java:147)
Exception in thread "main" java.lang.NullPointerException
at org.opencyc.api.ApiDemo.<init>(ApiDemo.java:56)
at org.opencyc.api.ApiDemo.main(ApiDemo.java:147)
Interruption while waiting Cyc connection establishment, closing sockets
Exception in thread "Thread-1" java.lang.NullPointerException
at org.opencyc.api.CycConnection$TaskProcessorBinaryResponseHandler.access$002(CycConnection.java:988)
at org.opencyc.api.CycConnection.close(CycConnection.java:268)
at org.opencyc.api.CycConnection$ConnectionTimer.run(CycConnection.java:1351)
Why is this happening? How can I connect to the cyc?
The problem is that your network settings do not allow you to connect to this machine. This is not a Java problem as such.
try
ping {hostname}
until this works, there is nothing you can do in java to work around this.
If you have the same version I have, it's trying to establish a connection to a Cyc image with the hostname and port defined by
CycConnection.DEFAULT_HOSTNAME
CycConnection.DEFAULT_BASE_PORT
You can find the proper values to use by evaluating the following in your Cyc image:
(get-machine-name)
*BASE-TCP-PORT*
Hope this works for you.
A dev on my team encountered this today, only their machine is seeing this issue out of many on the team.
Through much debugging we eventually discovered that localhost would not resolve for some reason. It would work in some JVM contexts and fail in others so it was completely inconsistent.
Replacing localhost with explicitly 127.0.0.1 fixed the issue. My hunch is that something was different with a local network and IPv6 perhaps, but we still don't really understand why this is the fix.
When I try to connect to cassandra within my java application I receive the exception at the end of this message. I am using pelops library to access database. Database is working on linux and my development environment is on windos 7. Intresting line is
WARNING: 10.0.0.7 NodeContext killing all pooled connections for session 44
10.0.0.7 is the IP of the cassandra node. And I can connect this node with cassandra-cli. After a few hours of googling I decided to ask, what i am doing wrong?
Complete stack trace is below.
SEVERE: org.apache.thrift.transport.TTransportException: java.net.ConnectException: Connection refused: connect
at org.apache.thrift.transport.TSocket.open(TSocket.java:185)
at org.wyki.cassandra.pelops.ThriftPool$Connection.open(ThriftPool.java:329)
at org.wyki.cassandra.pelops.ThriftPool$NodeContext.createConnection(ThriftPool.java:438)
at org.wyki.cassandra.pelops.ThriftPool$NodeContext.access$5(ThriftPool.java:429)
at org.wyki.cassandra.pelops.ThriftPool$NodeContext$1.run(ThriftPool.java:494)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at org.apache.thrift.transport.TSocket.open(TSocket.java:180)
... 7 more
WARNING: 10.0.0.7 NodeContext killing all pooled connections for session 44
"Connection refused" means that Cassandra isn't listening on the interface you're connecting to. By default Cassandra listens on port 9160 on localhost. You will need to change that if you want to connect externally; read the comments for ThriftAddress in the configuration file.
Pelops isn't doing anything remotely tricky when it comes to making connections to Cassandra so it seems very unlikely it's Pelops specific.
I've just had a quick look at the Hector connection code and it looks pretty much the same:
https://github.com/rantav/hector/blob/master/core/src/main/java/me/prettyprint/cassandra/connection/HThriftClient.java
The cassandra-cli code looks pretty much the same as well:
https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/cli/CliMain.java#L57
p.s. Cassandra should not be configured to listen on 0.0.0.0. See the "Why can't I make Cassandra listen on 0.0.0.0 (all my addresses)?" on the Cassandra FAQ.
It seems that this is a problem with pelops, which is a library on top of cassandra's thrift client. It has some problems for connection to Cassandra working on linux and client on a windows machine.
I've got the same exception connecting with "any" client to cassandra remotely:
ConnectException: Connection refused
Looking through SO I couldn't find a quick solution for that, just reading carefully through cassandra docs and comments within cassandra.yaml - they are very handy!
So for me worked following:
change rpc_address value to the hostname or ipaddress you are using to connect to the cassandra instance with the client
I get the following error when I try to run my project:
java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=169870080)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
Any ideas?
You're getting an ORA-12505 error ("TNS: listener could not resolve SID given in connection description."). This happens when the SID (System ID) of the database you wish to connect to isn't registered with Oracle's listener. If you can find the JDBC connection information, you may find something that matches this pattern:
jdbc:oracle:thin:[user]/[password]#[host]:[port]:[sid]
In this case, Oracle is telling you that [sid] does not exist on the server [host]. You may be connecting to the wrong server.
Connection refused means that the server is not allowing your client to connect. Double check the server settings and make sure your host is allowed to connect, at the very least.