i need help..to anyone who expert in servlet & Jsp..
my problem is..i do not know how to upload image via html/jsp..
>before that i already ask mr.google but.. i got sux answer.

so, this code work's and upload succesfully but it must manually put the destination file type string in this class >> File file = new File("C:/images/5.jpg");

import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class InsertImage extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
PrintWriter pw = response.getWriter();
String connectionURL = "jdbc:mysql://localhost:3306/test";
Connection con=null;
con = DriverManager.getConnection(connectionURL, "root", "");
PreparedStatement ps = con.prepareStatement("INSERT INTO pictures VALUES(?,?)");
File file = new File("C:/images/5.jpg");
FileInputStream fs = new FileInputStream(file);
int i = ps.executeUpdate();
pw.println("image inserted successfully");
pw.println("problem in image insertion");
} catch (Exception e){

then, when i try insert image using html/jsp form, it failed to insert that image into database.. and i got blank white screen.

here the html form..


<head><title>Image Upload</title></head>

	<form action="UploadImage.do" method="post" enctype="multipart/form-data" name="productForm" id="productForm"><br><br>
		<table width="400px" align="center" border=0 style="background-color:ffeeff;">
				<td align="center" colspan=2 style="font-weight:bold;font-size:20pt;">Image Details</td>

				<td align="center" colspan=2>&nbsp;</td>

				<td>Image Link: </td>
					<input type="file" name="file" id="file">

				<td><input type="submit" name="Submit" value="Submit"></td>
				<td colspan="2">&nbsp;</td>



and this is my xml.web


and this is mysql database.. field

CREATE TABLE `picture` (
`id` int(10) NOT NULL auto_increment,
`image` blob,

hope this info can help..thanks

Edited by peter_budo: Keep it Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

7 Years
Discussion Span
Last Post by stultuske

thanks peter.. it help a bit.. otherwise i'm still beginner to follow that particular method and of coz i need big time to understand all of that code function properly/perfectly..
but i need emergencies help to experties to modify my code above.. and my gol only insert image to mysql database via html/jsp form..


tu codigo esta bien ... el error es ...PreparedStatement ps = con.prepareStatement("INSERT INTO pictures VALUES(?,?)"); <--- "pictures" es "picture"

Votes + Comments
Not using English and then posting email address, bad!

Mounika, I think it's safe to say that after 3 years, either they found the sollution, or are no longer looking anyway.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.