throw org.sql2o.Sql2oException: Could not acquire a connection from DataSource - Communications link failure exception

806 views
Skip to first unread message

Zhiyuan Ma

unread,
Dec 20, 2016, 4:16:47 AM12/20/16
to sql2o
in my codes,

try (Connection con = sql2o.beginTransaction()) {
con.createQuery(del).executeUpdate();
log.debug("delete record aid:" + tid);

Query insertq = con.createQuery(insert);

for (Item item : li) {
insertq.addParameter("aid", tid)
.addParameter("type", type)
.addParameter("kw", item.kw)
.addParameter("rate", item.rate)
.addParameter("cid", item.cid)
.addParameter("year", item.year)
.addParameter("sort", item.sort)
.addParameter("date", LocalDate.now())
.addToBatch();
}
insertq.executeBatch();
con.commit();
log.debug("insert record aid = " + tid + " ,size = " + li.size());
}

sometimes, it throws an exception:

Exception in thread "main" org.sql2o.Sql2oException: Could not acquire a connection from DataSource - Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at org.sql2o.Connection.createConnection(Connection.java:291)
    at org.sql2o.Connection.<init>(Connection.java:51)
    at org.sql2o.Sql2o.beginTransaction(Sql2o.java:301)
    at org.sql2o.Sql2o.beginTransaction(Sql2o.java:320)
    at com.bftv.recsys.recItems.KeywordsDbWriter.toDB(KeywordsDbWriter.java:84)
    at com.bftv.recsys.recItems.KeywordsDbWriter.file2DB(KeywordsDbWriter.java:62)
    at com.bftv.recsys.recItems.KeywordsDbWriter.main(KeywordsDbWriter.java:36)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2251)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2284)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.GeneratedConstructorAccessor6.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:208)
    at org.sql2o.GenericDatasource.getConnection(GenericDatasource.java:62)
    at org.sql2o.Connection.createConnection(Connection.java:288)
    ... 6 more
Caused by: java.net.NoRouteToHostException: 无法指定被请求的地址 (Address not available)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:300)


some one know why?

Lars Aaberg

unread,
Dec 20, 2016, 5:58:49 AM12/20/16
to sql2o
This looks like a problem with the connection to your mysql server...

--
You received this message because you are subscribed to the Google Groups "sql2o" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sql2o+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages