PostgreSQL PGCopyOutputStream断开了连接

时间:2013-02-08 07:04:58

标签: postgresql postgresql-9.0

我遇到一个问题,我的数据库连接似乎从jdbc的COPY命令中途丢失(使用PGCopyOutputStream)。知道为什么会发生这种情况。我正在写一个包含两列整数的表。我在PostgreSQL 9.0.3

java.io.IOException: Write to copy failed.
at org.postgresql.copy.PGCopyOutputStream.write(PGCopyOutputStream.java:84) ~[postgresql-9.0-801.jdbc4.jar:na]
at org.postgresql.copy.PGCopyOutputStream.write(PGCopyOutputStream.java:76) ~[postgresql-9.0-801.jdbc4.jar:na]
at 
    ...
    ...
Caused by: org.postgresql.util.PSQLException: Database connection failed when writing to copy
at org.postgresql.core.v3.QueryExecutorImpl.writeToCopy(QueryExecutorImpl.java:856) ~[postgresql-9.0-801.jdbc4.jar:na]
at org.postgresql.core.v3.CopyInImpl.writeToCopy(CopyInImpl.java:53) ~[postgresql-9.0-801.jdbc4.jar:na]
at org.postgresql.copy.PGCopyOutputStream.writeToCopy(PGCopyOutputStream.java:125) ~[postgresql-9.0-801.jdbc4.jar:na]
at org.postgresql.copy.PGCopyOutputStream.write(PGCopyOutputStream.java:82) ~[postgresql-9.0-801.jdbc4.jar:na]
... 10 common frames omitted
Caused by: java.net.SocketException: Socket closed
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:116) ~[na:1.7.0_03]
at java.net.SocketOutputStream.write(SocketOutputStream.java:153) ~[na:1.7.0_03]
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) ~[na:1.7.0_03]
at java.io.BufferedOutputStream.write(BufferedOutputStream.java:95) ~[na:1.7.0_03]
at org.postgresql.core.PGStream.SendChar(PGStream.java:174) ~[postgresql-9.0-801.jdbc4.jar:na]
at org.postgresql.core.v3.QueryExecutorImpl.writeToCopy(QueryExecutorImpl.java:850) ~[postgresql-9.0-801.jdbc4.jar:na]
... 13 common frames omitted

1 个答案:

答案 0 :(得分:0)

由于早期的主键约束违规导致异常并使连接无法使用,因此发生了这种情况。