December 5, 2009 at 1:02 PM
Hi Friend,
We are providing you a code where we have retrieved three values from database i.e, name,address and photograph. We have created a table data(id,name,address,image.
import java.sql.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.ImageIO;
public class RetrieveData extends JFrame{
JLabel l1,l2,l3;
JLabel l;
JTextField t1,t2;
JTextArea area;
JScrollPane pane;
JPanel p;
RetrieveData(){
l1=new JLabel("Name");
l2=new JLabel("Address");
l3=new JLabel("Photograph");
t1=new JTextField(20);
t2=new JTextField(20);
p=new JPanel(new GridLayout(3,2));
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 name,address,image from data where id='2'");
byte[] bytes=new byte[1024];
String value1="";
String value2="";
if (rs.next()) {
value1=rs.getString("name");
value2=rs.getString("address");
bytes = rs.getBytes("image");
}
rs.close();
stmt.close();
con.close();
t1.setText(value1);
t2.setText(value2);
if (bytes != null) {
File f=new File("photograph.jpg");
InputStream in = new ByteArrayInputStream(bytes);
BufferedImage image = ImageIO.read(in);
ImageIO.write(image, "jpg", f);
String path=f.getName();
ImageIcon icon = createImageIcon(path,"a pretty but meaningless splat");
l = new JLabel(icon);
}
} catch (Exception e) {
}
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(l3);
p.add(l);
add(p);
setVisible(true);
setSize(400,200);
}
public static void main(String[]args){
RetrieveData data=new RetrieveData();
}
protected static ImageIcon createImageIcon(String path,String description) {
java.net.URL imgURL = RetrieveData.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL, description);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
}
Thanks
Related Tutorials/Questions & Answers:
how to retrive other details with an image - Swing AWThow to
retrive other details with an image hello
I m trying to
retrive an
image as well as some
other values from database..
but only
image.....
followingis my code..plz advice me
how to get both values as well as
image at a same
Advertisements
image retrive into DataBase - JDBCimage retrive into DataBase Dear Deepak Sir,
How to
retrive the
image into DataBase.
Thanks & Regards,
VijayaBabu.M Hi... shows you
how to retrieve
image from database using a servlet and then show
store and retrive image from the databasestore and
retrive image from the database please provide me with the code and the explanation of what each line does for the below query.
-
how to store and retreive images from sql database using sql commands
-
how to store
how to retrivehow to retrive this my servlet page..
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response
store and retrive image from database - JDBCstore and
retrive image from database
how to store and
retrive an
image in database using java? Hi friend,
Code for store
image...("Insert
Image Example!");
String driverName = "com.mysql.jdbc.Driver";
String
jsp retrive image - JSP-Interview Questionsjsp
retrive image
How to Display Images in JSP retrieved from MYSQL database?
plz help me.. Hi Friend,
Please visit the following link:
http://www.roseindia.net/jsp/retrieve-image.shtml
Thanks
how to access the details - Java Beginnershow to access the details
how to access the detailsclass E { String name; String no;string place; E(String n,String n,String p) { ... ... .... } public String... no)and
retrive all the
details of the person which is not given
image image Dear every body please help me
how to add and
retrive image and video into oracle 11g using jsp
how to retrive data grom database in jsp pages.how to
retrive data grom database in jsp pages. sir,
i have problem to retrieve data from table of the database on the html web pages , so would yuo please help me about this.
please post me solution on my email id
Show Other Image Effects Show
Other Image Effects
This section illustrates you some
other image effects... to describe
how a pixel affects its position in the
output
image of a filtering
how to insert data into database using jsp & retrivehow to insert data into database using jsp & retrive Hello,
I have created 1 html page which contain username, password & submit button. in my oracle10G database already contain table name admin which has name, password
How to move a file from a directory to other directoryHow to move a file from a directory to
other directory I tried the above example it will move the folder to
other directory but it does not move the
image file or
other file to a specified directory. Can anyone help me?
Thanks
How to extract details from XML? - JSP-ServletHow to extract
details from XML? I want to extract
details from http://service.openkapow.com/palanikumar/airportantigua.rest
How can i extract
details from this link?Here is my program...
Airport
How to display gridview details to labels dynamically?How to display gridview
details to labels dynamically? I am using SQLDataSource to connect to MySQL. I have a gridview that retrieves information... to display however, it always displays the
details of the previously selected id
how to set background imagehow to set background image
how to set
image in background in that
image i want over lay text
how it possible in jsp?
using flash
image how it is overlayed in jsp page?
thanks
image retreivalimage retreival I ve stored the path of
image and audio in mysql database.
how to
retrive it and display...
Can u pls help me out
How to store an image in databaseHow to store an
image in database Hi...........
How to store an
image in postgresql using a query. I mean tell me the way to store an
image using datatype.
I am using the datatype bytea but tell me
how to insert the
image How to store image into databaseHow to store
image into database Hi, all I want to store
image into database using Java. Can anyone help me that
how can i store
image into database... through the following link
How To Store
Image Into MySQL Using Java
Jmagick how to add image on an existing imageJmagick
how to add
image on an existing image hi,
I am using...) on an existing
image. can any one explains
how ?
Thanks.
hi,
In Jmagick you... you to understand
how to use these methods and values in to adding an
image how to grayscale an image in pythonhow to grayscale an
image in python Hi,
I have may images and it want to greyscale all with python.
can it be done?
how to grayscale an
image... example:
from PIL import
Image
img = Image.open('img.jpg').convert('LA')
img.save
How to write image in JmagickHow to write
image in Jmagick hi,
I am new in Java I am using the Jmagick library,
how can I write an
image in Jmagick ?
Thanks.
hi,
You can try this snippet into your code
ImageInfo ii = new ImageInfo("abc.jpg