gpt4 book ai didi

java - 如何将Java中的图片保存到多个blob中?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:24:47 25 4
gpt4 key购买 nike

正如我在标题中所述,我尝试使用 InputStream 多次访问图片文件,然后将其保存到 blob 类型的数据库,但第二次、第三次等的结果为空在。这是代码片段:

File image1 = new File("src/template1.png").getAbsoluteFile();
File image2 = new File("src/template2.png").getAbsoluteFile();
InputStream in1 = new FileInputStream(image1);
InputStream in2 = new FileInputStream(image2);
long length1 = image1.length();
long length2 = image2.length();
pstmt.setString(1, jTextField18.getText().toUpperCase());
pstmt.setBlob( 2, in1, length1 );
pstmt.setBlob( 3, in1, length1 );
pstmt.setBlob( 4, in1, length1 );
pstmt.setBlob( 5, in1, length1 );
pstmt.setBlob( 6, in1, length1 );
pstmt.setBlob( 7, in2, length2 );
Pstmt.setBlob( 8, in2, length2 );

那么结果是:

YR/21
[BLOB - 5.6 KiB]
[BLOB - 0 B]
[BLOB - 0 B]
[BLOB - 0 B]
[BLOB - 0 B]
[BLOB - 5.5 KiB]
[BLOB - 0 B]

我尝试像这段代码一样使用新的 InputStream,但发生了另一个错误。它说:行大小太大 (>8126)。将某些列更改为 TEXT 或 BLOB 或使用 ROW_FORMAT=DINAMIC 或 ROW_FORMAT=COMPRESSED 可能会有所帮助。在当前行格式中,768 字节的 BLOB 前缀被内联存储。

pstmt.setBlob( 2, in1, length1 );
image1 = new File("src/template1.png").getAbsoluteFile();
in1 = new FileInputStream(image1);
pstmt.setBlob( 3, in1, length1 );
image1 = new File("src/template1.png").getAbsoluteFile();
in1 = new FileInputStream(image1);
pstmt.setBlob( 4, in1, length1 );

我觉得问题已经解决了,换成另一个问题。谢谢解答

最佳答案

第一次调用消耗流,后续调用没有数据。每次调用都需要一个单独的 InputStream。

关于java - 如何将Java中的图片保存到多个blob中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23065497/

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