neelam
how to retrive other details with an image
1 Answer(s)      5 years and 6 months ago
Posted in : Swing AWT
Advertisement
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









Related Tutorials/Questions & Answers:
how to retrive other details with an image - Swing AWT
how 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
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
Advertisements
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
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 convert image into bytes and also retrive the image from that bytes - Java Beginners
how to convert image into bytes and also retrive the image from that bytes  how to convert image into bytes and also retrive the image from... = st1.executeQuery("select image from pictures where id='5'"); String imgLen
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
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 & 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
store and retrive image from database - JDBC
store 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
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
how to access the details - Java Beginners
how 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
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
retrive the result of a serach string from other sites - JSP-Servlet
retrive the result of a serach string from other sites  Sir, suppose i have create my own websites, and i want to search an item in my sites and as well as from other search sites and i want to show all the search result in my
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
jsp retrive image - JSP-Interview Questions
jsp 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
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 retrive an inmage from database and displaying it in imgae box - Swing AWT
How to retrive an inmage from database and displaying it in imgae box ...? I want to retrive an image from database and to display it in a small imagebox or pane in a JFrame.. is this possible? can you plz help tell me how we can do
how to develop student details using springs
how to develop student details using springs  how to develop student details using springs
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
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 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
how to get the details of username&password of mysql - JDBC
how to get the details of username&password of mysql  Hi friends, i installed mysql 5.5 on my system successfully,but the thing is i forgotten the username and password .please tell me how to get those details . Thanks
How to extract details from XML? - JSP-Servlet
How 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 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 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 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