How to display image from a blob column in oracle database using java
0 posts in topic
Thread View Thread View

How to display image from a blob column in oracle ...
Fri Nov 15, 2013 09:07 AM

I have been struggling for days now trying to figure out how I can display an image on a jLabel from a blob column in database but all efforts seems not sufficient to produce desired results. The problem is that the Label displays a dark colour stuff like background. Please help me out !. thanks. Here is the code segment I'm working with .....

PreparedStatement ps;          
             con = DriverManager.getConnection("jdbc:odbc:test", "SYSTEM", "VICTOR");
             ps = (PreparedStatement) con.prepareStatement("select Image from STUDENTDBASE.STUDENT_Images where STUDENT_ID = '" + id + "' ");
             result2 = ps.executeQuery();
             while (result2.next()){
                InputStream in = result2.getBinaryStream("Image");
               BufferedImage im = ImageIO.read(in);
               BufferedImage outimage = new BufferedImage(label.getWidth(), label.getHeight(), BufferedImage.TYPE_INT_RGB);
               Graphics2D g = outimage.createGraphics();
                float xScale = (float)label.getWidth() / outimage.getWidth();
                float yScale = (float)label.getHeight() / outimage.getHeight();
                AffineTransform at = AffineTransform.getScaleInstance(xScale,yScale);
                Image scaledImage = outimage.getScaledInstance(label.getWidth(), label.getHeight(), Image.SCALE_SMOOTH);
                ImageIcon icon = new ImageIcon(scaledImage);

I love Java with great passion
About | Sitemap | Contact