mutago 0 Newbie Poster

GOODAY experts, this code was to display an image from the database but when I runs it it displays an empty page, I tried to extend using Jframe but it still display an empty page. in my EXCEPTION I tried using PRINT STACK TRACE nowhere. please help me to fix the problem thanks

import java.sql.*;
import java.awt.*;
import javax.swing.*;

public class RetrieveImage {
	public static void main(String argv[]) {
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			Connection con = DriverManager.getConnection(
					"jdbc:mysql://localhost:3306/test", "root", "root");
			Statement stmt = con.createStatement();
			ResultSet rs = stmt
					.executeQuery("select image from image where image_id='3'");
			byte[] bytes = null;
			if (rs.next()) {
				bytes = rs.getBytes(1);
			}
			rs.close();
			stmt.close();
			con.close();
			if (bytes != null) {
				JFrame f = new JFrame();
				f.setTitle("Display Image From database");
				Image image = f.getToolkit().createImage(bytes);
				f.getContentPane().add(new Pane(image));
				f.setSize(300, 100);
				f.setVisible(true);
			}
		} catch (Exception e) {
		}
	}
}

class Pane extends JDesktopPane {
	private Image image;

	public Pane(Image image) {
		this.image = image;
	}

	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.drawImage(image, 0, 0, this);
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.