• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Uploading file in a database

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to uplaod an image file in a database through blob object...I have a jsp page where I insert the file and when I click the submit button a servlet is called.But how would I retrieve the name of that file in the servlet ?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sovan,
Why do you need the file name? Aren't you storing the contents? Search for "file upload" to get an open source library that reads the contents of an uploaded file.
 
sovan chatt
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Jeanne Boyarsky I had this code...Here file name is given in the servlet itself.But what I want to do is to retrieve the name of the file from the jsp page and use the following code..Why can't I do that?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can, but you are doing it very very wrong. Please see the JSP FAQ for information on properly handing file uploads. You do not read the uploaded file information from the file system -- you can't, in fact. The server has no access to the client's file system.

You need to read the information from the multi-part request, preferably using one of the popular 3rd party libraries for doing so. Trying to do it yourself is like hitting yourself with a hammer; best not done.
 
sovan chatt
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Bear Bibeault I just wanted to know how toretrieve the file name in the servlet ...please tell me how to do that..
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any updates for this .
 
Ranch Hand
Posts: 56
Eclipse IDE Postgres Database Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sovan chatt wrote: how toretrieve the file name in the servlet ...please tell me how to do that..



There are many ways to do this. One option is to use: org.apache.commons.fileupload.FileItem

String fileName = fileItem.getName();

I recommend you review this: http://commons.apache.org/fileupload/apidocs/org/apache/commons/fileupload/FileItem.html
 
sovan chatt
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When I try to run the above code I get an error message... java.sql.SQLException: Io exception: Connection reset by peer: socket write error .
Why??
 
sovan chatt
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had used the following query to create the table...
CREATE TABLE test (
`id` varchar2(10),
`image` blob,
PRIMARY KEY (`id`)
);
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic