`

Save/Write/Read image from/to a database table

 
阅读更多

The sample table is created as below to have a blob field to store file.

CREATE TABLE t1 (c1 INT PRIMARY KEY NOT NULL, c2 BLOB(5M));

Then use the below code snippet to insert an image file as follows.
 
PreparedStatement pstmt = conn.prepareStatement ("INSERT INTO t1 VALUES (?,?)");
pstmt.setInt (1, 100);
File fBlob = new File ( "image1.gif" );
FileInputStream is = new FileInputStream ( fBlob );
pstmt.setBinaryStream (2, is, (int) fBlob.length() );
pstmt.execute ();
...
 

Retrieving a BLOB or in other words retrieving the image file stored in the database as follows:
 
Statement stmt = conn.createStatement ();
ResultSet rs= stmt.executeQuery("SELECT * FROM t1");
while(rs.next()) {
int val1 = rs.getInt(1);
InputStream val2 = rs.getBinaryStream(2);
...
} rs.close();

分享到:
评论

相关推荐

    Laravel开发-laravel-pdf-to-image

    在上面的示例中,我们首先从上传的请求中获取 PDF 文件路径,然后使用 `PdfToImage::create()` 创建一个转换器对象,并调用 `saveImage()` 方法将 PDF 的第一页转换为 JPEG 图像并保存。最后,我们返回一个下载响应...

    PHP 图像处理组件:Intervention/image

    $image->save('public/new_image.jpg'); ``` 6. **颜色空间转换**:可以使用 `colorspace` 方法来转换图像的颜色空间。 ```php $image->colorspace(\Imagick::COLORSPACE_CMYK); ``` 7. **添加滤镜效果**:...

    DATABASE_image.rar_DATABASE_image_SQL SAVE IMAGE PUDN_SQL 图片_sql

    本文将深入探讨如何在数据库中管理图像数据,主要基于标题和描述中的关键词,如"database_image"、"sql_save_image_pudn"、"sql_图片"、"sql__image"和"sql_image_读取"。 首先,我们来讨论如何在SQL数据库中存储...

    dialog_write_image.zip_idl write image_write image IDL

    filename = DLG_OPEN('Select an image file to write...', 1, '*.tif;*.tiff;*.png;*.jpg') if filename ne '' then begin write_image, filename, image_data end ``` 这段代码会弹出一个对话框,让用户选择一个....

    DIZipWriter v6.2.0 for D7-XE10.1 ZIP 压缩 解压缩

    // Save a TBitMap image to a ZIP archive. // Create and initialize a bitmap image. Img := TBitMap.Create; // Add a new entry to the ZIP archive. DIZipWriter.AddEntry('MyImage'); // Write the ...

    SimpleImage.zip

    ->toFile('new-image.png', 'image/png') // convert to PNG and save a copy to new-image.png ->toScreen(); // output to the screen // And much more! } catch(Exception $err) { // Handle errors echo...

    C# 对SqlServer中Image字段的读写(例子)

    Image imageToSave = Image.FromFile("path_to_your_image.jpg"); using (var memoryStream = new MemoryStream()) { imageToSave.Save(memoryStream, ImageFormat.Jpeg); imageData = memoryStream.ToArray();...

    GifDecoder

    * Creates new frame image from current data (and previous * frames as specified by their disposition codes). */ protected void setPixels() { // expose destination image's pixels as int array int...

    PHP图像处理和操作库InterventionImage.zip

    Intervention Image 是一个 PHP 图像处理和操作库,它提供了一个简单的,易于表达的方式来创建、编辑图片。...// save image in desired format $img->save('public/bar.jpg'); 标签:Intervention

    pb图片处理nvo_image.sru

    save要保存到的文件名(包含路径) format图片的根式,根据图片相应的类型指定。目前可用以下参数 image/bmp image/jpeg image/gif image/tiff image/png width指定图片宽度 height指定图片高度...

    FlexCel Reports 2.53 for D5/6/7

    操纵Excel极好的控件,包含源代码、例程、帮助FlexCel Reports is a suite of Delphi 5/6/7 components allowing to create Excel files by substituting values into a Template from a database or variables....

    delphi 7 gif控件

    // from 2003-02-28 to 2003-03-05 where white (255,255,255) in a bitmap // // was converted to (254,254,254) in the gif. // // The doCreateOptimizedPaletteFromSingleBitmap function and // // the ...

    Laravel开发-laravel-image

    Image::make($request->file('image'))->save('s3://my-bucket/path/to/image.jpg'); ``` ### 总结 `laravel-image`为Laravel开发者提供了一个高效、易用的图像处理解决方案。通过简单的API,它可以满足从基本的...

    SQLiteExpertSetup

    Save/Load SQL scripts to/from file. 10. Transaction support. SQLite supports one level of transactions. 11. Data mapping. SQLite Expert supports custom data types, and 40 predefined data types. ...

    Stud_PE2.6最新版

    -Resource viewer/editor (save/replace ico/cur/bmp); Pe Scanner (PEiD sig database): -400 packers/protectors/compilers; Task viewer/dumper/killer; PEHeader/Binary file compare; RVA to RAW to RVA...

    SQLiteExpertSetup.exe.part1

    9. Save/Load SQL scripts to/from file. 10. Transaction support. SQLite supports one level of transactions. 11. Data mapping. SQLite Expert supports custom data types, and 40 predefined data types. ...

    SQLiteExpertSetup.exe.part2

    9. Save/Load SQL scripts to/from file. 10. Transaction support. SQLite supports one level of transactions. 11. Data mapping. SQLite Expert supports custom data types, and 40 predefined data types. ...

    vue-cli项目修改文件热重载失效的解决方法

    在webstrom系统设置中有一项配置,是 Use “safe write”(save changes to a temporary file first) 。webstrom是自动保存的,如果勾选Use “safe write”,编辑的文件首先会保存到临时文件中,如果保存操作成功,则...

    Using openCV to load, gray and save image

    Using openCV to load image, and transfer to gray and save image.

    Download an Image and Save it as PNG or JPEG in iPhone SDK

    func saveImage(_ imageData: Data, format: ImageFormat) { guard let image = UIImage(data: imageData) else { // 处理无效数据 return } let filename = "image\(format.rawValue).\(format.extension)" ...

Global site tag (gtag.js) - Google Analytics