A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Java
»
JSP
Author
photo upload using jsp
geomar lubaton
Greenhorn
Joined: Apr 27, 2005
Posts: 1
posted
Apr 27, 2005 19:37:00
0
How do you upload a photo in jsp? And I also have to save it in my database... i used postgresql. Can anyone please help me.. I really need to finish my webapp asap. Thanks.
Smitha Kochunny
Greenhorn
Joined: Apr 27, 2005
Posts: 2
posted
Apr 28, 2005 00:34:00
0
Hi,
Try using UploadBean (
http://www.javazoom.net/jzservlets/uploadbean/uploadbean.html
).
Thank You,
Smitha.
Adeel Ansari
Ranch Hand
Joined: Aug 15, 2004
Posts: 2874
posted
Apr 28, 2005 01:12:00
0
http://jakarta.apache.org/commons/fileupload/
.
And for database stuff please post in
JDBC
Forum. You will find better answers there.
Thanks.
deshdeep divakar
Ranch Hand
Joined: Apr 19, 2004
Posts: 91
posted
Apr 30, 2005 22:51:00
0
Try this
import java.io.*; import java.sql.*; import java.util.*; public class StoreFile1 { Connection con=null; public StoreFile1() { } public void getFile(String filename1) throws Exception { System.out.println("Before DataBase Connection1"); PreparedStatement pst = null; ResultSet rs=null; String s1="gif"; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc :-o dbc:RT"," "," "); pst = con.prepareStatement("select images from pic where ftype=?"); pst.setString(1,filename1); rs=pst.executeQuery(); while(rs.next()) { byte[] b=rs.getBytes("images"); System.out.println("b size= "+b.length); if(filename1.equals(s1)) { FileOutputStream fos=new FileOutputStream(new File(".gif ")); fos.write(b,0,b.length); fos.flush(); fos.close(); } else { FileOutputStream fos=new FileOutputStream(new File(".jpg ")); fos.write(b,0,b.length); fos.flush(); fos.close(); } } System.out.println("File Written Successfully"); } catch(Exception e) { System.out.println(" Problem : "+e); } finally { con.close(); pst.close(); } } public static void main(String args[]) throws Exception { StoreFile1 store1=new StoreFile1(); System.out.println("What is The File Description "); String filename1 = new BufferedReader(new InputStreamReader(System.in)).readLine(); store1.getFile(filename1); } }
Change Table name and attribute names as per ur requirments
"Do not be afraid of going slow, be afraid of standing still"
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: photo upload using jsp
Similar Threads
struts dojo + displaytags clashing
How to upload a file?
retrieve photo
How to retrieve new images uploaded on the server into jsp without restarting the server?
Essay exam scheduled in advance?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter