Insert and Retrieve Image

Insert and Retrieve Image

View Answers

May 9, 2008 at 9:14 PM

Hi friend,


This is insert image code


<%@ page language="java" import="java.sql.*,java.util.*,java.io.*,java.awt.image.BufferedImage,java.io.ByteArrayOutputStream,java.io.InputStream,java.text.*" %>

<%

Connection con = null;
String url = "jdbc:mysql://192.168.10.211:3306/";;
String db = "amar";
String driver ="com.mysql.jdbc.Driver";
String userName ="amar" ;
String password ="amar123" ;
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,userName,password);
PreparedStatement pst = con.prepareStatement("insert into uploadfile values(?,?,?)");
File file = new File("C:/apache-tomcat-5.5.23/webapps/jsp/red_rose2.gif");
FileInputStream fis = new FileInputStream(file);
pst.setString(1, "amar");
pst.setString(2, "kumar");
pst.setBinaryStream(3,fis,fis.available());
int i = pst.executeUpdate();
if(i!=0){
out.println("image has been inserted");
}
else{
out.println("image is not inserted");
}
}
catch (Exception e){
System.out.println(e);
}

%>


-----------------------------------

This is Retrive image code

<%@ page language="java" session="true"
import= "
java.awt.image.BufferedImage,java.io.ByteArrayOutputStream,java.io.InputStream,java.sql.Blob,java.sql.Connection,
java.sql.ResultSet,javax.swing.ImageIcon,java.sql.*" %>

<%
try
{
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch(ClassNotFoundException e)
{ System.out.println(e);
}
String url = "jdbc:mysql://192.168.10.211:3306/";;
String db = "register";
String userName ="amar" ;
String password ="amar123" ;
Connection con;
con = DriverManager.getConnection(url+db,userName,password);
String query = "SELECT image from uploadfile where firstname = 'amardeep'";
out.println(query);
ResultSet rs = con.createStatement().executeQuery(query);
if(rs.next()) {
byte[] bytearray = new byte[4096];
int size=0;
InputStream image;
image = rs.getBinaryStream(1);
response.reset();
response.setContentType("image/gif");
while((size=image.read(bytearray))!= -1 ){
response.getOutputStream().write(bytearray,0,size);
}
response.flushBuffer();
image.close();
rs.close();
}
}
catch (Exception exc)
{ System.out.println(exc);
}

%>


---------------------------------------


Read for more information,

http://www.roseindia.net/jsp/









Related Tutorials/Questions & Answers:
Insert and Retrieve Image - JSP-Servlet
Insert and Retrieve Image  Hello, I need source code using java servlet or jsp and html form and brief explanations on how to insert and retrieve..., This is insert image code
Insert or retrieve image into oracle 10g by using java
Insert or retrieve image into oracle 10g by using java   How can i insert or retrieve image into oracle10g using java plz i need it urgently,need guidance to do this plz
Advertisements
how to insert and retrieve an image from mysql using java - Java Beginners
how to insert and retrieve an image from mysql using java  how to insert and retrieve an image from mysql using java?  Hi friend, Code to insert image using java : import java.sql.*; import java.io.*; class
how to insert image into server
how to insert image into server  how to insert an image into sql server and retrieve it using jSP
Image retrieve
Image retrieve  HI.. store image path/data Java Coding. ... It's supposed to take the image, store it in a directory as well as pass the image path to mysql database... Now I want to retrieve the data from directory using path
Struts insert & retrieve
Struts insert & retrieve  Give a struts prg to insert and retrieve data from mysql db using the struts tags(no jsp scriplets and expressions) following mvc arch. i.e. model containing db connectivity, form containing get &
image retrieve - Java Beginners
Image Retrieve  How to retrieve the image from mysql field using java
insert image using hibernate
insert image using hibernate  Sir, Today I hadposted question regarding upload image, th answer you had given is using SQL, but I am using Hibernate to insert data in the same table where I want to insert image. Plz hlp me
hibernate insert image
hibernate insert image  Sir, Today I hadposted question regarding upload image, th answer you had given is using SQL, but I am using Hibernate to insert data in the same table where I want to insert image. Plz hlp me. Thanks
insert image - JSP-Servlet
insert image  hi friends i am mahesh i am trying to insert image... = connection.prepareStatement("insert into save_image(name, image) values...("unsucessfull to insert image."); } psmnt.close(); connection.close
image insert - Java Beginners
image insert  i browsed the image by clicking d browse button.if i press submit button means d image automatically stored in db.then i have 2 retrieve d image separately...................... Untitled Document
How to store and retrieve image from database in JSP?
How to store and retrieve image from database in JSP?  Hi, In one... and retrieve image from database in JSP? Thanks   HI, You can use one program to insert image into database. Check the tutorial: Uploading
Insert image in database
Insert image in database  Want a jsp-struts program in which the imageFile is in the form of getter and setter and inserted in the database as a Blob using . and then download the image and show on next jsp pg. No use
How to retrieve image from database
How to retrieve image from database  hi........ How to retrieve image from database when it is stored. I have stored image in postgresql and want to retrieve in java form. Can u tel me hw to do? I am trying n able to do also
how to store and retrieve image from database
how to store and retrieve image from database  how to store and retrieve images into database(oracle) and how to retrive images from database using jsp   Here is a jsp code that insert and retrieve image from mysql
How to retrieve image from database in Servlet?
How to retrieve image from database in Servlet?  Hi, How to retrieve image from database in Servlet? Thanks   Hi, Please check the tutorial Retrieve image from database using Servlet. Thanks
insert image in JFrame - Development process
insert image in JFrame  how to insert a image in JFrame.please... Panel { BufferedImage image; public ShowImage() { try { System.out.println("Enter image name\n"); BufferedReader bf=new BufferedReader(new
how to insert, retrieve data from,to db(code)....
how to insert, retrieve data from,to db(code)....  Hi..... i ve created login page n in that a registration form also.... my doubt is-when... that data will b stored in db(m using sybase). 2.also hw to retrieve the data from
how to insert, retrieve data from,to db(code)....
how to insert, retrieve data from,to db(code)....  Hi, i have created login page n in that a registration form also in jsp, my doubt is-when new user... will b stored in db(m using sybase). 2.also hw to retrieve the data from db. cn u
How to retrieve blob image from database in JSP?
How to retrieve blob image from database in JSP?  Hello, JSP is used... the blog image from database. How to retrieve blob image from database in JSP?   Hi, Please check the tutorial Retrieve image from database using
Can i insert image into struts text field
Can i insert image into struts text field  please tell me can i insert image into text field
How to retrieve image from mysql database in JSP?
How to retrieve image from mysql database in JSP?  Hi, I need JSP... to retrieve image from mysql database in JSP? Thanks   Hi, You can write... the stream. Once image data is retrieve you can send the data to client browser
How to retrieve and display image from database in Java?
How to retrieve and display image from database in Java?  Hi, I am... on the web page. My application is in Java/JSP. How to retrieve and display image.... Please check the it at How to store and retrieve image from database in JSP
how to insert the physical path of an image in database - JDBC
how to insert the physical path of an image in database  hello I m working in a project where we have to capture an image using web cam. when... , the image column is of varchar datatype.. plz can you tell me how to insert image's
how to store and then immediately retrieve when store the image into database?
how to store and then immediately retrieve when store the image into database?  how to store and then immediately retrieve when store the image into database?   Here is a jsp code that insert and retrieve image from
<img src=""> using retrieve image from database using jsp
using retrieve image from database using jsp  how to <img src="" > tag using retrieve image from database and display in jsp
how to store and retrieve image using struts2 and hibernate integration
how to store and retrieve image using struts2 and hibernate integration  how to store and retrieve image using struts2 and hibernate integration? plz help !! thanks in advance
how we retrieve image from database
how we retrieve image from database  my code is:- $search=$_POST...;lt;/table&amp;amp;gt;"; mysql_close($con);   PHP retrieve image... save the path of image in product row with the help of long blob..and i required
Insert Image In DB through Servlet - JSP-Servlet
Insert Image In DB through Servlet  Dear Sir, I want to add the Image In databse using servlet. I have a program Its fine run on command prompt...()); } } } Whether Any entry will be made in web.xml when Insert Image in Databse using servlet
Insert Image In DB through Servlet - JSP-Servlet
Insert Image In DB through Servlet  Dear Sir, My previous Query...(e.getMessage()); } } } Whether Any entry will be made in web.xml when Insert Image..., To insert image in Database using servlet to visit.... http://www.roseindia.net
Insert Image into Excel Sheet
Insert Image into Excel Sheet In this section, you will learn how to insert image into excel sheet using Apache POI. In the given below example, am image is insert into excel sheet at row 1 and at column 1. you can specify the top
Insert Image in DB through Servlet - JSP-Servlet
Insert Image in DB through Servlet  Dear Sir, My previous Query...(e.getMessage()); } } } Whether Any entry will be made in web.xml when Insert Image... Dear Sir, I already see this reference link which you give to insert the image
How to retrieve image from database using jsp and servlet?
How to retrieve image from database using jsp and servlet?  Hi, I am trying to find code for displaying the image from database in a JSP page. How to retrieve image from database using jsp and servlet
Insert Image In DB through Servlet - JSP-Servlet
Insert Image In DB through Servlet  Dear Sir, My previous Query...(e.getMessage()); } } } Whether Any entry will be made in web.xml when Insert Image...("insert into Image(id,imgName,image) values (?,?,?)"); File file= new File
how to send and retrieve image along with text to and from database
how to send and retrieve image along with text to and from database  ... image generator. im so stumped right now and i dont know how to combine the two. i want to take the random image along with the text and send it to another user
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
insert name city and upload image in database using mysql and jsp
insert name city and upload image in database using mysql and jsp   insert name city and upload image in database using mysql and jsp
Insert Image in DB through Servlet - JSP-Servlet
Insert Image in DB through Servlet  Dear Sir, You write me: copy this link and paste in your Url http://rs236.rapidshare.com/files/144453519/New... A new Page displayed, check there a Round Shaped Image Called "download" click
How to insert image in sql database from user using servlet
How to insert image in sql database from user using servlet  pls tell me accept image from user and insert image in sql server 2005 database using servlet and jsp
Insert Image in DB through Servlet - JSP-Servlet
Insert Image in DB through Servlet  Dear Sir, I am not able to solve my problem cocerning Inserting the image in Database through Servlet. I am usng... = conn.prepareStatement("insert into MyPictures values(?,?,?)"); pre.setInt(1,5
To retrieve image from SQL Server Database - Java Server Faces Questions
To retrieve image from SQL Server Database  Sir/Madam, I am trying to retrieve image from SQL Server 2000 database in Visual Web JSF Page using NetBeans IDE 6.0. Is it possible to display image in Data Table Component
How To Store Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java
How To Store Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java  How To Store... and then retrieve them in image gallery using java
How To Retrieve Image From From MySQL Using Java
How To Retrieve Image From From MySQL Using Java In this section we will discuss about how to retrieve image from the MySQL using Java. This example explains you about all the steps that how to retrieve image from MySQL database
Insert image from user using and save in database
Insert image from user using and save in database  when i am trying to upload a image from user and trying to save into oracle9i database... = connection.prepareStatement("insert into file(file_data) values(?)"); fis = new
how to retrieve image from mysql using java - Java Beginners
how to retrieve image from mysql using java  hi i am using jsf and java IDE netbean,database mysql.how to retrieve image from mysql database. please help me   Hi friend, I am sending you a link. I hope
Retrieve image from database using servlet and display in JSP
Retrieve image from database using servlet and display in JSP  Hi, I am total new to JSP although I am learning it for the last few days. Now I want to use MySQL Database from JSP page. How to retrieve image from database using
How to insert image in PDF file in struts2
How to insert image in PDF file in struts2 In this example, we will see how to insert image in PDF file using struts2.2.1 framework.. index.jsp <html>ADS_TO_REPLACE_1 <head><title>Insert title here<
Retrieve image from mysql database through jsp
Retrieve image from mysql database through jsp... to retrieve image from mysql database through jsp code. First create a database... on the basis of  'id' field of the table. So code will retrieve image of specified
insert name city image in database using mysql and jsp
insert name city image in database using mysql and jsp  how to insert... is an example in jsp that insert name, city and image to database. <%@ page import..."); PreparedStatement psmt=con.prepareStatement("insert into data(name,city,image)"+"values
How to insert and retrieve Questions with special symbols and images into database in an ONLINE EXAMINATION project?
How to insert and retrieve Questions with special symbols and images... is " how can I insert the questions with some symbols and images into database?". and how can I retrieve them to randomize

Ads