-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplayHelper.java
35 lines (31 loc) · 982 Bytes
/
DisplayHelper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.awt.Image;
import javax.swing.ImageIcon;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Blob;
import java.io.InputStream;
import javax.imageio.ImageIO;
public class DisplayHelper {
public static ImageIcon getImageIconById(int id,Connection con)
{
ImageIcon icon=null;
try{
String sql="select pic from images where id=?";
PreparedStatement pt=con.prepareStatement(sql);
pt.setInt(1,id);
ResultSet set=pt.executeQuery();
if(set.next())
{
Blob b=set.getBlob("pic");
InputStream is=b.getBinaryStream();
Image image=ImageIO.read(is);
icon=new ImageIcon(image);
}
}catch(Exception e)
{
e.printStackTrace();
}
return icon;
}
}