gpt4 book ai didi

java - 流已被读取且已到达文件末尾且无法重复使用

转载 作者:搜寻专家 更新时间:2023-10-30 20:16:56 24 4
gpt4 key购买 nike

我创建了一个 Derby 数据库,创建了一个包含 BLOB 列“pic”作为列之一的表。

现在我正在尝试将 .jpg 文件从本地存储到此 BLOB 字段。我写了下面的代码,我试图用本地镜像更新每一行的 BLOB 列,然后再次读取表格并获取 BLOB 并存储回本地文件夹。

public static void main(String[] args) {
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
String dbURL = "jdbc:derby:D:/software/derby/derby/bin/MyDbTest";
Connection conn1 = DriverManager.getConnection(dbURL);
if (conn1 != null) {
System.out.println("Connected to database #1");
}
PreparedStatement stmt = conn1
.prepareStatement("update PRACTICEEMPLOYEEDB set pic = ?");
File f1 =new File(
"D:\\Users\\abkale\\Downloads\\asd.jpg");
InputStream in = new FileInputStream(f1);
stmt.setBinaryStream(1, in,f1.length());
stmt.execute(); //LINE 1 :Place where exception in being thrown
conn1.commit();

Statement s = conn1.createStatement();
ResultSet rs1=s.executeQuery("select * from practiceemployeedb");
int i=0;
while(rs1.next()){
//Some code to read columns and print/store
}

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

但是在上面的代码中,我在 //LINE 1 上遇到了以下错误:::

Connected to database #1
java.sql.SQLException: An unexpected exception was thrown
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.execute(Unknown Source)
at derby.ConnectionProvider.main(ConnectionProvider.java:33)
Caused by: ERROR XSDA4: An unexpected exception was thrown
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 11 more
Caused by: java.io.EOFException: Stream has already been read and end-of-file reached and cannot be re-used.
at org.apache.derby.iapi.types.RawToBinaryFormatStream.read(Unknown Source)
at org.apache.derby.impl.store.raw.data.MemByteHolder.write(Unknown Source)
at org.apache.derby.impl.store.raw.data.RememberBytesInputStream.fillBuf(Unknown Source)
at org.apache.derby.impl.store.raw.data.StoredPage.logColumn(Unknown Source)
at org.apache.derby.impl.store.raw.data.StoredPage.logRow(Unknown Source)
at org.apache.derby.impl.store.raw.data.UpdateOperation.writeOptionalDataToBuffer(Unknown Source)
at org.apache.derby.impl.store.raw.data.UpdateOperation.<init>(Unknown Source)
at org.apache.derby.impl.store.raw.data.LoggableActions.actionUpdate(Unknown Source)
at org.apache.derby.impl.store.raw.data.StoredPage.doUpdateAtSlot(Unknown Source)
at org.apache.derby.impl.store.raw.data.BasePage.updateAtSlot(Unknown Source)
at org.apache.derby.impl.store.access.conglomerate.GenericConglomerateController.replace(Unknown Source)
at org.apache.derby.impl.sql.execute.RowChangerImpl.updateRow(Unknown Source)
at org.apache.derby.impl.sql.execute.UpdateResultSet.collectAffectedRows(Unknown Source)
at org.apache.derby.impl.sql.execute.UpdateResultSet.open(Unknown Source)
at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source)
... 4 more

我不明白我做错了什么有人能帮忙吗?

最佳答案

您不能使用同一流更新多行。创建一个 where 子句以在您的语句中选择一行,它应该可以工作。

据报告,此错误仅在嵌入式驱动程序和客户端驱动程序中失败。更多 info这里。

此外,根据 this ,此问题仅影响版本 10.9.1.0 和 10.10.2.0。这是否在更高版本中重新出现,或者您正在使用其中之一?

关于java - 流已被读取且已到达文件末尾且无法重复使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34692954/

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