你好,我正在使用sql developer 3.0。
我需要将图像作为BLOB存储在表中。
我创建了一个表,如下所示:CREATE TABLE Account_images(img_id NUMBER, MP_ID NUMBER, icon BLOB);
我需要存储的图像在
'C:Projectimages'
任何人请帮助我插入图像到数据库与sql查询??
-
将您的图像存储在文件中。
文件图像=新文件("C: 图片 image.jpg项目");
-
Sql查询insert.
String Sql="insert into Account_images(img_id,img_id,icon) values(1,1,?)";
-
保存声明
PreparedStatement pStatement = connection.prepareStatement (sql);
-
将文件写入FileInputStream
FileInputStream fis =fis = new FileInputStream(image);
-
将fis附加到preparedStatement作为
pStatement。setBinaryStream (1 fis fis.length ());
-
执行语句
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();