Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Insert and Retrieve Image
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Emmanuel Aigbovbiosa
Insert and Retrieve Image
1 Answer(s)      6 years and 9 months ago
Posted in : JSP-Servlet



Advertisement
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
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
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
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
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
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
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 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
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
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 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 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
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
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
<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
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 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..., To insert image in Database using servlet to visit.... http://www.roseindia.net
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
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 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
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
 

 

 

DMCA.com