Showing posts with label JLabel. Show all posts
Showing posts with label JLabel. Show all posts

Friday, December 9, 2011

Inserting and Retrieving images to sqlite

I tried with BinaryStream and Blob but both don't work properly.
Blob is not implemented with sqlite jdbc driver.

Note : setBytes() , getBytes() works properly with sqlite.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sqliteimagetest;

import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

Showing an Image

file path -> FileInputStream -> BufferedImage -> Image -> ImageIcon

   1 File imageFile=new File("C:\\garden.jpg");
   2 try {
   3     FileInputStream fis=new FileInputStream(imageFile);
   4     
   5     BufferedImage buffImg=ImageIO.read(fis);
   6     Image img=Toolkit.getDefaultToolkit().createImage(buffImg.getSource());
   7     ImageIcon imgico=new ImageIcon(img);
   8     jLabel1.setIcon(imgico);
   9     
  10 } catch (Exception e) {
  11     System.out.println("Error : " + e.getMessage());
  12 }

JLabel only supports ImageIcon type.


© kani.stack.notez 2012 | Blogger Template by Enny Law - Ngetik Dot Com - Nulis