gpt4 book ai didi

java - 需要帮助-在sql Developer3.0中查询将图像插入表中

转载 作者:行者123 更新时间:2023-12-01 04:47:45 25 4
gpt4 key购买 nike

您好,我正在使用 sql Developer 3.0。

我需要将图像作为 BLOB 存储在表中。

我创建了一个表,如下所示:

CREATE TABLE Account_images(img_id NUMBER, MP_ID NUMBER, icon BLOB);

我需要存储的图像位于

'C:\Project\images\'

有人可以帮我用sql查询将图像插入数据库吗?

提前致谢。

最佳答案

  1. 将图像存储在文件中。

    文件图像=new file("'C:\Project\images\image.jpg");

  2. 要插入的 SQL 查询。

    String Sql="插入Account_images(img_id,img_id,icon)值(1,1,?)";

  3. 准备声明

    PreparedStatement pStatement=connection.prepareStatement(sql);

  4. 将文件写入 FileInputStream

    FileInputStream fis =fis = new FileInputStream(image);

  5. 将 fis 附加到准备好的语句

    pStatement.setBinaryStream(1, fis,fis.length());

  6. 执行语句

    ResultSet result=pStatement.executeUpdate();

整体

File image=new file("'C:\Project\images\image.jpg");
String Sql="insert into Account_images(img_id,img_id,icon) values(1,1,?)";
PreparedStatement pStatement=connection.prepareStatement(sql);
FileInputStream fis =fis = new FileInputStream(image);
pStatement.setBinaryStream(1, fis,fis.length());
ResultSet result=pStatement.executeUpdate();

关于java - 需要帮助-在sql Developer3.0中查询将图像插入表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15544527/

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