I am loading data in Solr from MongoDB.
SolrInputDocument doc = new SolrInputDocument();
BasicDBObject record = (BasicDBObject) cursor.next();
doc.addField("_id", record.get("_id"));
// add more fields
server.add(doc);
server.commit();
I am getting below exception.
Exception in thread "main" org.apache.solr.client.solrj.SolrServerException: java.net.ConnectException: Connection timed out: connect
at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:483)
at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:244)
at org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:105)
at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:64)
Caused by: java.net.ConnectException: Connection timed out: connect
This code worked for me before. I did not change anything in the code. But now its giving error after adding few documents. What's wrong here?
Related
I'm facing the following errors while connecting oracle DB, I'm using spring boot JDBC template to connect to database. The errors are below,
Exception in thread "main" java.lang.Exception: java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
at com.falabella.util.OracleDB.main(OracleDB.java:70)
Caused by: java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:392)
Caused by: java.net.UnknownHostException: NODE-01: nodename nor servname provided, or not known
Below are my finding, My database server host having the cluster and it has two nodes, like below,
Cluster (wood.clsuter.com)
| NODE01 (wood-01)
| NODE02 (wood-02)
My connection string is like this, jdbc:oracle:thin:#wood-clsuter.com:1531/service_name
When I'm using the cluster name in the connection string, I'm facing the below error
Caused by: java.net.UnknownHostException: wood-01: nodename nor servname provided, or not known
Whereas if I use any of the node name in the connection string , able to connect Data base without any issue, the working connection string is like below,
jdbc:oracle:thin:#wood-01.com:1531/service_name or
jdbc:oracle:thin:#wood-02.com:1531/service_name
Since I need to use my DB requests as load balancing, I need to use the cluster name instead of slave nodes,
I would like to know the root cause of this issue, such kind of production environment issues,
Could you please help me out with this?
You need to change connect string to:
"jdbc:oracle:thin:#(DESCRIPTION=(FAILOVER=ON)(LOAD_BALANCE=ON)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=wood-01.com)(PORT = 1531))(ADDRESS = (PROTOCOL = TCP)(HOST = wood-02.com)(PORT = 1531)))(CONNECT_DATA=(SERVICE_NAME =service_name)(FAILOVER_MODE=(TYPE=select)(METHOD=basic))))"
I'm trying to connect to mongodb server which is running on remote Linux machine using java code,
public static void main(String[] args) {
Properties prop = new Properties();
try {
//load a properties file
prop.load(new FileInputStream("src/main/resources/mongodb.properties"));
String server = prop.getProperty("server");
String port = prop.getProperty("port");
int portnum = Integer.parseInt(port);
/**** Connect to MongoDB ****/
MongoClient mongo = new MongoClient(server,portnum);
System.out.println("Connected to database");
/**** Get database ****/
// if database doesn't exists, MongoDB will create it for you
DB db = mongo.getDB("test");
/**** Get collection / table from 'details' ****/
// if collection doesn't exists, MongoDB will create it for you
DBCollection table = db.getCollection("details");
/**** Insert ****/
// create a document to store key and value
BasicDBObject document = new BasicDBObject();
document.put("name", "test");
document.put("age", 24);
table.insert(document);
/**** Find and display ****/
BasicDBObject searchQuery = new BasicDBObject();
searchQuery.put("name", "test");
DBCursor cursor = table.find(searchQuery);
while (cursor.hasNext()) {
System.out.println(cursor.next());
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
It is working fine with my local mongo. But facing an issue while trying to connect with linux server.
Here is the error message,
Jan 18, 2016 12:23:02 AM com.mongodb.DBTCPConnector initDirectConnection
WARNING: Exception executing isMaster command on server:port
java.io.IOException: couldn't connect to [server port] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:214)
at com.mongodb.DBPort.go(DBPort.java:107)
at com.mongodb.DBPort.go(DBPort.java:88)
at com.mongodb.DBPort.findOne(DBPort.java:143)
at com.mongodb.DBPort.runCommand(DBPort.java:148)
at com.mongodb.DBTCPConnector.initDirectConnection(DBTCPConnector.java:548)
at com.mongodb.Mongo.getMaxBsonObjectSize(Mongo.java:620)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:254)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:226)
at com.mongodb.DBCollection.insert(DBCollection.java:75)
at com.mongodb.DBCollection.insert(DBCollection.java:59)
at com.mongodb.DBCollection.insert(DBCollection.java:104)
at com.filecompare.util.MongoDBConnection.main(MongoDBConnection.java:42)
Jan 18, 2016 12:23:03 AM com.mongodb.DBTCPConnector initDirectConnection
WARNING: Exception executing isMaster command on sever port
java.io.IOException: couldn't connect to [server port] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:214)
at com.mongodb.DBPort.go(DBPort.java:107)
at com.mongodb.DBPort.go(DBPort.java:88)
at com.mongodb.DBPort.findOne(DBPort.java:143)
at com.mongodb.DBPort.runCommand(DBPort.java:148)
at com.mongodb.DBTCPConnector.initDirectConnection(DBTCPConnector.java:548)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:527)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:174)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:155)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:270)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:226)
at com.mongodb.DBCollection.insert(DBCollection.java:75)
at com.mongodb.DBCollection.insert(DBCollection.java:59)
at com.mongodb.DBCollection.insert(DBCollection.java:104)
at com.filecompare.util.MongoDBConnection.main(MongoDBConnection.java:42)
Jan 18, 2016 12:23:04 AM com.mongodb.DBPortPool gotError
WARNING: emptying DBPortPool to server:port b/c of error
java.io.IOException: couldn't connect to [server:port] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:214)
at com.mongodb.DBPort.go(DBPort.java:107)
at com.mongodb.DBPort.go(DBPort.java:84)
at com.mongodb.DBPort.say(DBPort.java:79)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:181)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:155)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:270)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:226)
at com.mongodb.DBCollection.insert(DBCollection.java:75)
at com.mongodb.DBCollection.insert(DBCollection.java:59)
at com.mongodb.DBCollection.insert(DBCollection.java:104)
at com.filecompare.util.MongoDBConnection.main(MongoDBConnection.java:42)
Exception in thread "main" com.mongodb.MongoException$Network: can't say something
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:194)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:155)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:270)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:226)
at com.mongodb.DBCollection.insert(DBCollection.java:75)
at com.mongodb.DBCollection.insert(DBCollection.java:59)
at com.mongodb.DBCollection.insert(DBCollection.java:104)
at com.filecompare.util.MongoDBConnection.main(MongoDBConnection.java:42)
Caused by: java.io.IOException: couldn't connect to [server port] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:214)
at com.mongodb.DBPort.go(DBPort.java:107)
at com.mongodb.DBPort.go(DBPort.java:84)
at com.mongodb.DBPort.say(DBPort.java:79)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:181)
... 7 more
Steps that I generally follow to connect with mongo on linux are,
Login to server using Putty(windows) or ssh command(Mac).
type in mongo.
Connected to mongo, run mongo commands to view/ insert data.
But, in above java code I didn't include any login credentials. Do I have to do that. If so, could someone please guide me.
Are you sure you're providing the right values for your server and port property variables in mongodb.properties?
Default port for MongoDB is 27017.
Also, check your mongod.conf on the MongoDB server. This file is found, by default at /etc/mongod.conf and look for the following attribute:
bind_ip = 127.0.0.1
If this is set to 127.0.0.1 or localhost, then you won't be able to access your MongoDB server publicly from outside.
Now to fix this, change value of bind_ip to include your public ip address, so if your public address is 46.12.212.34, bind_ip will look like:
bind_ip = 127.0.0.1, 46.12.212.34
Save and exit the file and restart your MongoDB database. Your Java application should now work.
my java code is like:
logger.info("start");
getJdbcTemplate().execute("call " + procedureName + "()");
and I got the exception:
org.springframework.dao.DataAccessResourceFailureException: StatementCallback; SQL [call PRMI_UPDATE_USER_LOGIN_INFO()]; Io ERROR: Connection reset; nested exception is java.sql.SQLException: Io ERROR: Connection reset
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:257)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:407)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:428)
Maybe it's caused by the long time waiting. I found that it printed "start" in log and after about 5 minutes I got the exception.
update at 2013-03-13:
I got that exception not only at calling oracle stored procedure but at druid's 'JdbcUtil.close(...)':
com.alibaba.druid.util.JdbcUtils.close:81 - close connection error
java.sql.SQLRecoverableException: Io Error: Connection reset
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:101)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:263)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:521)
at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:500)
at oracle.jdbc.driver.PhysicalConnection.close(PhysicalConnection.java:3509)
at com.alibaba.druid.filter.FilterChainImpl.connection_close(FilterChainImpl.java:167)
at com.alibaba.druid.filter.stat.StatFilter.connection_close(StatFilter.java:254)
at com.alibaba.druid.filter.FilterChainImpl.connection_close(FilterChainImpl.java:163)
at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.close(ConnectionProxyImpl.java:115)
at com.alibaba.druid.util.JdbcUtils.close(JdbcUtils.java:79)
at com.alibaba.druid.pool.DruidDataSource.shrink(DruidDataSource.java:1876)
at com.alibaba.druid.pool.DruidDataSource$DestroyConnectionThread.run(DruidDataSource.java:1694)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:96)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at oracle.net.ns.DataPacket.send(DataPacket.java:150)
at oracle.net.ns.NetOutputStream.flush(NetOutputStream.java:180)
at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:169)
at oracle.net.ns.NetInputStream.read(NetInputStream.java:117)
at oracle.net.ns.NetInputStream.read(NetInputStream.java:92)
at oracle.net.ns.NetInputStream.read(NetInputStream.java:77)
at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1034)
at oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:1010)
at oracle.jdbc.driver.T4C7Ocommoncall.receive(T4C7Ocommoncall.java:97)
at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:487)
The druid's JdbcUtil.close method is quite simple:
public static void close(Connection x) {
if (x == null) {
return;
}
try {
x.close();
} catch (Exception e) {
LOG.debug("close connection error", e);
}
}
the source code is :
https://github.com/alibaba/druid/blob/master/src/main/java/com/alibaba/druid/util/JdbcUtils.java
It should wait as long as it is needed. Forget about various hacks which try to "detect" deadlock based on timeout delay.
you should find also some ORA-XXXX error. Io ERROR: Connection reset does not look like Oracle error message, there should be some error number attached to it
the timeout 5 minutes is very strange value. Theoretically this can be setup also on database side. As profile parameter CPU_PER_CALL but in such a case you should get an error: ORA-02393: exceeded call limit on CPU usage. And you connection should NOT be lost
theoretically you can also have problems which dead connection detection, but 5 minutes timeout is too short for that
another possible source can be ORA-600 error. Oracle internal error, maybe your session process crashed and therefore TCP connection was lost
you should contact your local DBAs and ask then for cooperation. They should help you better than anonymous people on the Internet forum.
Maybe it's caused by the long time waiting
No it is not caused due to that
As Java Doc says about DataAccessResourceFailureException
Data access exception thrown when a resource fails completely: for
example, if we can't connect to a database using JDBC.
I am getting following error when i try to run Oozie workflow using java
IO_ERROR : java.net.ConnectException: Connection timed out: connect
at org.apache.oozie.client.OozieClient.validateWSVersion(OozieClient.java:234)
at org.apache.oozie.client.OozieClient.createURL(OozieClient.java:300)
at org.apache.oozie.client.OozieClient.access$000(OozieClient.java:71)
at org.apache.oozie.client.OozieClient$ClientCallable.call(OozieClient.java:366)
at org.apache.oozie.client.OozieClient.run(OozieClient.java:547)
at oozieDemo.main(oozieDemo.java:27)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
Here is my code:
OozieClient wc = new OozieClient("http:xxxxxxx/oozie");
System.out.println(" connection established....." + wc);
Properties conf = wc.createConfiguration();
conf.setProperty(OozieClient.APP_PATH,"hdfs:foo/xxx/workflow.xml");
conf.setProperty("jobTracker", "foo:8021");
conf.setProperty("nameNode","hdfs:xxxx");
conf.setProperty("queueName", "default");
conf.setProperty("appLibLoc","hdfs:/foo/xxx/lib");
String jobId = wc.run(conf);
System.out.println("Workflow job submitted");
So here I can see connection is getting established but unable to run the workflow.
I am new to this. So can't figure it out where exactly it is failing.
Connection timeout means either:
URL is incorrect or down, try pinging it.
Firewall is blocking it.
Default timeout expired.
Your internet access is down, which I'm going to assume isn't the case.
I'm a newbie of java programming, and I'm trying to learning.
I have a database mysql and I manage the connection with connection Pool, BoneCP is the library that I use.
The code for create a Pool is this:
BoneCPConfig config = new BoneCPConfig(); // create a new configuration object
config.setJdbcUrl( R.database.url + R.database.dbName ); // set the JDBC url
config.setUsername( R.database.userName ); // set the username
config.setPassword( R.database.password ); // set the password
config.setMinConnectionsPerPartition(2);
config.setMaxConnectionsPerPartition(5);
config.setPartitionCount( 3 );
try{
connectionPool = new BoneCP( config ); // setup the connection pool
}catch( Exception e ){
System.out.println( e );
}
When i need the connection for send query to DB i catch the connection with this line of code:
conn = R.database.connectionPool.getConnection();
I think is all ok at this point and I haven't any errors.
After a min the console say this:
[BoneCP-pool-watch-thread] ERROR com.jolbox.bonecp.BoneCP - Failed to acquire connection to jdbc:mysql://localhost:3306/test_db. Sleeping for 7000 ms. Attempts left: 0
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test_db
at java.sql.DriverManager.getConnection(DriverManager.java:596)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:363)
at com.jolbox.bonecp.BoneCP.obtainInternalConnection(BoneCP.java:269)
at com.jolbox.bonecp.ConnectionHandle.<init>(ConnectionHandle.java:242)
at com.jolbox.bonecp.PoolWatchThread.fillConnections(PoolWatchThread.java:115)
at com.jolbox.bonecp.PoolWatchThread.run(PoolWatchThread.java:82)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
[BoneCP-pool-watch-thread] ERROR com.jolbox.bonecp.CustomThreadFactory - Uncaught Exception in thread BoneCP-pool-watch-thread
java.lang.NoClassDefFoundError: com/jolbox/bonecp/hooks/ConnectionState
at com.jolbox.bonecp.ConnectionHandle.markPossiblyBroken(ConnectionHandle.java:382)
at com.jolbox.bonecp.ConnectionHandle.<init>(ConnectionHandle.java:244)
at com.jolbox.bonecp.PoolWatchThread.fillConnections(PoolWatchThread.java:115)
at com.jolbox.bonecp.PoolWatchThread.run(PoolWatchThread.java:82)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
This is the strange problem!!
Thank very much!!
No suitable driver found for jdbc:mysql://localhost:3306/test_db
This seems to imply that you don't have a java MySQL JDBC driver on your classpath, have a look at the available connectors for MySQL and make sure the appropriate JAR including this driver is on your classpath.
MySQL Connectors