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

View Answers

November 27, 2010 at 3:13 PM

Hi Friend,

Try the following code:

<%@page import="java.sql.*,java.io.*"%>
<%
try{
    InputStream sImage;
Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
File imgfile = new File("C:/rose.jpg");
      FileInputStream fin = new FileInputStream(imgfile);
      PreparedStatement pre = con.prepareStatement("insert into user values(?,?,?,?)");
      pre.setInt(1,1);
      pre.setString(2,"A");
      pre.setString(3,"Delhi");
      pre.setBinaryStream(4,fin,(int)imgfile.length());
      pre.executeUpdate();
      System.out.println("Inserting Successfully!");
      pre.close();
      Statement st=con.createStatement();
      ResultSet rs=st.executeQuery("select image from user where id=1");
if(rs.next()) {
byte[] bytearray = new byte[1048576];
int size=0;
sImage = rs.getBinaryStream(1);
response.reset();
response.setContentType("image/jpeg");
while((size=sImage.read(bytearray))!= -1 ){
response.getOutputStream().write(bytearray,0,size);
}
}
rs.close();
st.close();
con.close();
}
catch(Exception ex){
out.println("error :"+ex);
}
%>

Thanks









Related Tutorials/Questions & Answers:
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
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
Advertisements
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
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... , the image column is of varchar datatype.. plz can you tell me how to insert image's path.. and also how to retrive that image path and show that picture in a small
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<
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
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
How to save image on the server by applet
How to save image on the server by applet  HI, in my project I am using applet and creating a chart by jcchart. Now when the chart has ploated... as a gif image on the server directory. Can any Body help me how can I do it Thanks
How to save image on the server by applet
How to save image on the server by applet  HI, in my project I am using applet and creating a chart by jcchart. Now when the chart has ploated... as a gif image on the server directory. Can any Body help me how can I do it Thanks
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 insert and retreive an image in mysql database using spring mvc framework???
How to insert and retreive an image in mysql database using spring mvc framework???  I ve solved this problem based on the Product Search Application. Those who need this concept and code segment kindly copy it. Thanks and All
How to Insert image and data both together in database in JSP/Servlet ?
How to Insert image and data both together in database in JSP/Servlet ? ... = connection.prepareStatement("insert into data(Name,City,Img) values('"+nn+"','"+cc...(e.getMessage()); } } %> //if i remove below lines then it insert
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
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 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
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
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
how to insert array data into sql server using jsp
how to insert array data into sql server using jsp  hello, i have problem to insert array data into my sql server from jsp form. beloW is my code... from form, but not insert into my sql database. try { //String
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
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 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
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....   dear sir or madam, i wont to How to Store Image Into The Database
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 Oracle 10g. On server side of weblogic Its show that: Connection loaded
How to insert image in MySQL database using sql query?
. The video of this tutorial show you how you can insert the image into database... tutorial of "How to insert image in MySQL database using sql query?": So...Insert image in MySQL database using sql query  
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
To scan a image and upload to server
To scan a image and upload to server  I am beginner of JavaME I want a code to scan a image and upload to server
How can store image in server folder when deployed with a .war file?
How can store image in server folder when deployed with a .war file?  Hi all; When I am using application.getRealPath() , it return null when deployed with a .war file and when I use hard code it shows syntax error or path
how to insert check box
how to insert check box   how to insert check box into jtable row in swing
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
scan a image and upload to server
scan a image and upload to server  Hai i am beginner of Java ME..I want the code To scan a image and upload to server
How to upload image to server in j2me by multipart/form-data?
How to upload image to server in j2me by multipart/form-data?  Hi, I need upload data to java server from j2me 1.Two text messages and 3 capture...) at java.lang.Thread.run(Unknown Source) From J2me I am using code to upload image to server
scan a image and upload to server
and upload to server..after capture that image decoded it going to be convert digit value....My client want to scan a image and upload to server in j2me please refer me,to send a code for to scan a image and upload to server in j2me Thanks
Capture a image and upload to server
Capture a image and upload to server  Hai team i have trouble to capture a image and upload to server in java me........... So i want a code immediately,.......To capture a image and upload to server in j2me...... If you give
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
Image uploading in FTP Server
Image uploading in FTP Server  I want to upload images to a ftp server every 1 hour automatically using java..please help
How to insert rows in jTable?
How to insert rows in jTable?  Hi, I need to take input from user using JTable. I want an empty row to appear after clicking a insert button... not figure out how to. I used DefaultTableModel but wasnt able to insert a row
Upload image to the server in J2ME?
Upload image to the server in J2ME?  HI Team, I am new to the j2me and now I am working on the program that, upload captured image to the server by using j2me. I did this by using simulator but when I made hit from the mobile
How to insert clob data??
How to insert clob data??  Can any one tell me in details how... to insert more than 4000 characters.I have heard that clob fields can hold 4 gb of data and need pl/sql to avail that feature.Can any one tell me how to create
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
how to insert a summary values in grid
how to insert a summary values in grid  how to insert a summary value in grid
ModuleNotFoundError: No module named 'image-source-server'
named 'image-source-server' How to remove the ModuleNotFoundError: No module named 'image-source-server' error? Thanks   Hi...ModuleNotFoundError: No module named 'image-source-server'  Hi, My
how to insert value in dynamic table
how to insert value in dynamic table  i am creating a project... sql server showing a syntax error. my code is as follows:- PreparedStatement ps1=con.prepareStatement("insert into "+company+year+"(firstname,lastname,email
Uploading Multiple Image On Server?
Uploading Multiple Image On Server?  Hello sir, I am stuck with a problem of uploading multiple images on server. i have done a code which works fine for uploading single image,but it doesn't work with uploading multiple

Ads