Save Image in Database.
//import com.oreilly.servlet.MultipartRequest;
import java.io.*;
import java.sql.*;
import javax.servlet.http.*;
import javax.servlet.*;
//import org.apache.commons.fileupload.disk.DiskFileItemFactory;
//import org.apache.commons.fileupload.servlet.ServletFileUpload;
public class UploadServlet extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
//MultipartRequest m=new MultipartRequest(request,"c:/test");
//String image=request.getParameter("image");
//out.println(image);
try
{
//DiskFileItemFactory factory = new DiskFileItemFactory();
// ServletFileUpload sfu = new ServletFileUpload(factory);
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/file","root","root");
PreparedStatement ps=con.prepareStatement("insert into load1(image) values (?)");
//out.println(""+con+""+ps);
File file = new File("F:\\wallpaper\\girls\\CELINA11.JPG");
//out.println(""+file);
FileInputStream fin=new FileInputStream(file);
//out.println(""+fin);
ps.setBinaryStream(1,fin,fin.available());
ps.executeUpdate();
out.print("successfully uploaded");
}
catch(Exception e)
{
System.out.println(e);
}
}
}