EmployeeShow.java Source code

Java tutorial

Introduction

Here is the source code for EmployeeShow.java

Source

import java.io.ObjectInputStream;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.swing.ImageIcon;

public class EmployeeShow {

    public static void main(String[] args) throws Exception {
        ImageIcon image;

        Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/c:\\employee");

        Statement s = con.createStatement();
        ResultSet rs = s.executeQuery("select photo from employee where name = 'Duke'");
        if (rs.next()) {
            Blob photo = rs.getBlob(1);
            ObjectInputStream ois = null;
            ois = new ObjectInputStream(photo.getBinaryStream());
            image = (ImageIcon) ois.readObject();
        }
        s.close();
    }
}