gpt4 book ai didi

java - 抛出 java.net.SocketException 的代码

转载 作者:行者123 更新时间:2023-12-01 10:34:46 24 4
gpt4 key购买 nike

我正在使用 c3p0 连接池方法从远程数据库请求一些数据。我可以很好地检索我需要的所有数据,但由于某种原因,这似乎与网络套接字有关,我根据此堆栈跟踪得到 java.net.SocketException:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
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:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1137)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3697)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3586)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4131)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2597)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2758)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2820)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2769)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1569)
at com.mchange.v2.c3p0.impl.NewProxyStatement.executeQuery(NewProxyStatement.java:327)
at MemsqlRequester.run(MemsqlRequester.java:28)
Caused by: java.net.SocketException: Connection timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:112)
at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:159)
at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:187)
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3140)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3597)
... 9 more
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
at java.util.Vector.get(Vector.java:748)
at GraphTransformer$$anonfun$getTxInformationList$1.apply$mcVI$sp(GraphTransformer.scala:38)
at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:141)
at GraphTransformer.getTxInformationList(GraphTransformer.scala:37)
at GraphTransformer.getFeaturesTx(GraphTransformer.scala:62)
at GraphTransformer.getFeatures(GraphTransformer.scala:327)
at GraphDatasetBuilder.lambda$publishGraphFeaturesFromMemsql$13(GraphDatasetBuilder.java:62)
at java.util.Vector.forEach(Vector.java:1249)
at GraphDatasetBuilder.publishGraphFeaturesFromMemsql(GraphDatasetBuilder.java:59)
at GraphDatasetBuilder.main(GraphDatasetBuilder.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:674)
at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:180)
at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:205)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:120)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

基本上,我执行语句调用以从远程数据集中检索数据的代码片段如下:

try {
...
Statement stmt = connection.createStatement();
rs = stmt.executeQuery(this.queryList.get(queryIndex)); // According to the stack trace, here is where I'm getting the SocketException
...
} catch (SQLException ex) {
ex.printStackTrace();
}

问题是我可以在这段代码周围添加任何catch子句,因为它告诉我没有抛出SocketException。基本上我的问题是这里出了什么问题,考虑到显然我无法处理堆栈跟踪中所述的代码中的 SocketException 。

最佳答案

您发布的堆栈跟踪不完整,我们无法看到引发了什么异常。

如果您无法捕获 SocketException,我认为您收到的异常是不同的。

SocketException 被驱动程序捕获并作为不同的异常重新抛出。您在堆栈跟踪中看到的 SocketException 只是“引起的”,即已捕获的原始异常。

更新

您无法捕获 SocketException,因为它不是您收到的异常。请粘贴完整的堆栈跟踪。

ArrayIndexOutOfBoundsException 似乎是一个新异常。我可能是错的,但我不认为驱动程序会抛出 ArrayIndexOutOfBoundsException。这个异常似乎是由 Spark 引发的。

我不太确定,但在我看来:

1)网络问题,无法访问数据库并打开连接;

2) 驱动程序中抛出SocketException;

3) 这个异常被捕获并作为另一个异常重新抛出(堆栈跟踪不完整,抛出的异常还不可见,但我猜这是一个 CommunicationsException);

4) 因此,尝试读取图形的 Spark 代码失败并抛出 ArrayIndexOutOfBoundsException;

关于java - 抛出 java.net.SocketException 的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34833397/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com