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



Home Answers Viewqa JSP-Servlet Insert Image In DB through Servlet
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Vijay
Insert Image In DB through Servlet
3 Answer(s)      6 years and 2 months ago
Posted in : JSP-Servlet



Advertisement
View Answers

September 12, 2008 at 12:07 AM


Hello

I am Using java1.5 with MyEclipse and JBoss4.0, mysql
So you change little bit in web.xml
I upload a file in this link , download it

http://rapidshare.com/files/144453519/New_WinZip_File.zip.html

Thanks
Rajanikant


September 12, 2008 at 10:54 AM


Hi vijay,


This is Servlet code:

package javacode;

import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.Blob;
import java.io.*;

class RetriveImage {
FileOutputStream image;
Connection con = null;
PreparedStatement pstmt = null;
Statement stmt= null;
ResultSet res = null;
StringBuffer query=null;
String filename = "javacode/rose.jpg";
String driverName = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://192.168.10.211:3306/";;
String dbName = "amar";
String userName = "amar";
String password = "amar123";

public RetriveImage(){
try{
query=new StringBuffer("insert into Image(id,imgName,image) values (?,?,?)");
File file= new File(filename);
Class.forName(driverName);
con = DriverManager.getConnection(url+dbName,userName,password);
stmt=con.createStatement();
pstmt=con.prepareStatement(query.toString());
pstmt.setInt(1, 97);
pstmt.setString(2,"rose");
pstmt.setBinaryStream(3, new FileInputStream(filename),(int)file.length());
pstmt.executeUpdate();
System.out.println("Successfully display image from database .....");
ResultSet rs=stmt.executeQuery("select * from Image where image='image'");
if (rs.next()) {
Blob test=rs.getBlob("image");
InputStream x=test.getBinaryStream();
int size=x.available();
OutputStream out=new FileOutputStream("javacode/rose.jpg");
byte b[]= new byte[size];
x.read(b);
out.write(b);
}
}
catch(ClassNotFoundException cnfe){
System.out.println("ClassNotFoundException occured :"+cnfe);
}
catch(SQLException se){
System.out.println("SQLException occured :"+se);
}
catch(FileNotFoundException fe){
System.out.println("File Not Found Exception occured :"+fe);
}
catch(Exception e){
System.out.println("Exception occured :"+e);
}
finally{
try{
stmt.close();
con.close();
}
catch(Exception e){
System.out.println(e);
}
}
}
public static void main(String args[]) throws IOException{
RetriveImage ri = new RetriveImage();
}
}





September 12, 2008 at 3:12 PM


Hi friend,


I think, problem in your web.xml file. So plz change the web.xml file


<servlet>
<servlet-name>servletLocation</servlet-name>
<servlet-class>ServletLocation</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>servletLocation</servlet-name>
<url-pattern>/ServletLocation</url-pattern>
</servlet-mapping>


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

Visit for more information:

http://www.roseindia.net/servlets/

Thanks


Related Tutorials/Questions & Answers:
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 that: I want to add the Image In databse using servlet. I have a program Its fine..., To insert image in Database using servlet to visit.... http://www.roseindia.net
Advertisements
Insert Image in DB through Servlet - JSP-Servlet
Insert Image in DB through Servlet  Dear Sir, My previous Query that: I want to add the Image In databse using servlet. I have a program Its fine...(e.getMessage()); } } } Whether Any entry will be made in web.xml when Insert Image
Insert Image In DB through Servlet - JSP-Servlet
Insert Image In DB through Servlet  Dear Sir, My previous Query that: I want to add the Image In databse using servlet. I have a program Its fine...(e.getMessage()); } } } Whether Any entry will be made in web.xml when Insert Image
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
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
DB Insert
DB Insert  How to insert XML data into a database column? Column data type is CLOB
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
Upload Image to Database through Servlet - JSP-Servlet
Upload Image to Database through Servlet  Hello, I make a application from where I upload the Image from local disk then store in DB.Before storing the Image in DB I want to check this program. I include the commons
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
Need Help-How to store input parameter in DB through Java Bean - JSP-Servlet
Need Help-How to store input parameter in DB through Java Bean  Hello...(Its Java Bean) which create a connection from DB and insert the data. At run time servlet and server also show that loggging are saved in DB. But when I
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
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
Todd oracle DB connection through PHP
Todd oracle DB connection through PHP  Can u please explain how to connect Todd oracle DB using PHP & What are the setups we need to perform? Thanks
JSP:select image for db and display in image tag
JSP:select image for db and display in image tag  Hi, i am new to this forum. My query is that, i am trying to display image in image tag but i am...(); response.setContentType("image/jpg"); response.getOutputStream().write(rb,0,len
JSP:select image for db and display in image tag
JSP:select image for db and display in image tag  Hi, i am new to this forum. My query is that, i am trying to display image in tag but i am...(); response.setContentType("image/jpg"); response.getOutputStream().write(rb,0,len
JSP:select image for db and display in image tag
JSP:select image for db and display in image tag  Hi, i am new to this forum. My query is that, i am trying to display image in tag but i am...(); response.setContentType("image/jpg"); response.getOutputStream().write(rb,0,len
Insert  Image into Database Using Servlet
Insert  Image into Database Using Servlet   ... of inserting image into database table using Servlet. This type of program is useful... to retrieve the image from database using Servlet. After retrieving the image from
Insert Image into Database Using Servlet
Insert  Image into Database Using Servlet   ... image into database table using Servlet. This type of program is useful in social... the image from database using Servlet. After retrieving the image from database
how to insert, retrieve data from,to db(code)....
how to insert, retrieve data from,to db(code)....  Hi..... i ve... that data will b stored in db(m using sybase). 2.also hw to retrieve the data from db. cn u plz tel me the code in detail.n i thk it shud b written in jdbc
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
JSP,DB,SERVLET
JSP,DB,SERVLET  hi thank you for your reply.With this code i can insert the data successfully into database but once i give submit button... the code for the same scenario using for populating data into database through
how to insert, retrieve data from,to db(code)....
how to insert, retrieve data from,to db(code)....  Hi, i have created... will b stored in db(m using sybase). 2.also hw to retrieve the data from db. cn u... that i cn understd perfectly.   Please go through the following links
JSP,DB,SERVLET
JSP,DB,SERVLET  I have a jsp page called page1.jsp with 3 text fields name,phone ,city.i populated these datas into a database table through servlet... should be automatically populated from database through servlet
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
JSP,DB,SERVLET
JSP,DB,SERVLET  I have a jsp page with 3 text fields name,age ,city.i populated these datas into a database table.I have another jsp page with 4... be automatically populated from database throush servlet..Can u give me the code
Saving image and text in mysql db using spring?
Saving image and text in mysql db using spring?  Hii, My requirement is to save the employee details(including image) into mysql db.i want to save the image location in db .And actual image(binary formate) should save
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
JSP,DB,SERVLET
JSP,DB,SERVLET  hi thank you for your reply.With this code i can insert the data successfully into database but In ajax.jsp once i give the name..."); Statement st=con.createStatement(); int i=st.executeUpdate("insert
 

 

 

DMCA.com