需要帮助- sql developer3.0中插入图像到表中的查询



你好,我正在使用sql developer 3.0。

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

我创建了一个表,如下所示:
CREATE TABLE Account_images(img_id NUMBER, MP_ID NUMBER, icon BLOB);

我需要存储的图像在

'C:Projectimages'

任何人请帮助我插入图像到数据库与sql查询??

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

    文件图像=新文件("C: 图片 image.jpg项目");

  2. Sql查询insert.

    String Sql="insert into Account_images(img_id,img_id,icon) values(1,1,?)";

  3. 保存声明

    PreparedStatement pStatement = connection.prepareStatement (sql);

  4. 将文件写入FileInputStream

    FileInputStream fis =fis = new FileInputStream(image);

  5. 将fis附加到preparedStatement作为

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

  6. 执行语句

    ResultSet结果= pStatement.executeUpdate ();

作为一个整体

File image=new file("'C:Projectimagesimage.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();

最新更新