how to retrive other details with an image

Ads
 

how to retrive other details with an image

View Answers

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

Ads









Related Tutorials/Questions & Answers:
retrive the employee details with image from mysql database using jsp servlet
retrive the employee details with image from mysql database using jsp servlet  im doing the web project to retrive the employee profile which i stored in the database using jsp servlet then want to show the result in the next jsp
how to display or retrive an image in jsp whose path is stored in oracle database
how to display or retrive an image in jsp whose path is stored in oracle database  how to display or retrive an image in jsp whose path is stored in oracle database and the image is stored in my pictures folder
Advertisements
image retrive into DataBase - JDBC
image 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
how to retrive
how 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 the database
store 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
store & retrive the image from oracle database
store & retrive the image from oracle database  how can i store the image path in tha database & fetch that image from oracle database
retrive image from database using jsp without stream
retrive image from database using jsp without stream  How to retrive image from database using jsp without stream like (inputStream
How to copy an jpeg image from one folder to other folder using jsp
How to copy an jpeg image from one folder to other folder using jsp  How to copy an image from one folder to another folder using jsp
How can I write a GUI stack program by Java to push Image files instead of other data type items?
How can I write a GUI stack program by Java to push Image files instead of other data type items?   How can I write a GUI stack program by Java to push Image files instead of other data type items? for the push instruction I
How to copy an jpeg image from one folder to other folder using jsp
How to copy an jpeg image from one folder to other folder using jsp  hello, i am creating photo gallery where from admin side i allow admin to browse... be in my image folder...so,How to copy an jpeg image from one folder to other
after entering details in reg page,n enter the submit button,how can v store the data in db, n hw can v retrive the data frm db in jsp
after entering details in reg page,n enter the submit button,how can v store the data in db, n hw can v retrive the data frm db in jsp  i ve creted... the submit button,how can v store the data in db, n hw can v retrive the data frm
insert and retrive image from sql server database in jsp
insert and retrive image from sql server database in jsp  what is the code to insert and retrive an image from sql server database in jsp
upload file and insert other details to database using a single form
upload file and insert other details to database using a single form   hi.. I have problem with uploading a file and insert other user datas together... but my other details seem to be null
how to code-updating some details n some details r unchanged
how to code-updating some details n some details r unchanged  i have created a page with empty text boxes,details are.... house... : bloodgroup : my requirement is to update the details of user. and i had written
How to move a file from a directory to other directory
How 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 develop student details using springs
how to develop student details using springs  how to develop student details using springs
How to retrive database information using servlet and disply in table format in browser
How to retrive database information using servlet and disply in table format in browser  Hi, any one send code how to retrive the data base information in table format in web browser
image displaying from database with some other information
image displaying from database with some other information  hi, in the following section of code when i am not displaying the image it is working properly but when i tried to display the image nothing is displayed on browser
How to retrive a particular record from database in php with mysql?
How to retrive a particular record from database in php with mysql?  ... names are username,password,email,firstname,lastname. But i want to retrive 3 rd record based on username and password. I dont know how to retrive in php with mysql
how retrive data from google analystics dashbord on the client machine
how retrive data from google analystics dashbord on the client machine   sir i am digvijay subj: retrive data from google analystics dashbord respected sir, According above subject i request you , i want retrive data from
how to update image in php
how to update image in php  how to update image in php
How to put an image on a JButton?
How to put an image on a JButton?  How to put an image on a JButton
how to insert data into database using jsp & retrive
how 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 can retrive value from combo box in servlet?
how can retrive value from combo box in servlet?  i have a jsp page with combobox. And i want to get value from combox to servlet
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 image
how 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
image   Dear every body please help me how to add and retrive image and video into oracle 11g using jsp
How to Display Font Other than english
How to Display Font Other than english  How to display font other than english without using any files installed
How to store an image in database
How 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 database
How 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
how to display image with listview
how to display image with listview  How can i display the list view with the related images from database

Ads