User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 392,036 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,284 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 325 | Replies: 0
Reply
Join Date: Jan 2008
Posts: 5
Reputation: jatin29 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jatin29 jatin29 is offline Offline
Newbie Poster

problem in uploading image

  #1  
Feb 19th, 2008
hi ..problem in uploading image..using servlet to upload image in mysql..use html form so user given the path of image..but giving error.here is the code..help me on this.




import java.sql.*;
import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class LoadImage extends HttpServlet{

public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
entrance(req, res);
}
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
entrance(req, res);
}
public void entrance(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String photo=req.getParameter("photo");

Connection conn = null;
PreparedStatement ps = null;
try
{
Class.forName( "com.mysql.jdbc.Driver" );

conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/first","root","root");
ps = conn.prepareStatement("INSERT INTO uplo (photo) VALUES( ? )" );


File image = new File( photo );
FileInputStream fis = new FileInputStream( image );
ps.setBinaryStream(1, fis, ( int )image.length() );

// Execute the INSERT
int count = ps.executeUpdate();
System.out.println( "Rows inserted: " + count );
}
catch( Exception e )
{
e.printStackTrace();
}
finally
{
try
{
if( ps != null ) ps.close();
if( conn != null ) conn.close();
}
catch( Exception ee )
{
ee.printStackTrace();
}
}
}
}
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Java Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 11:02 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC