I am facing problem in storing an image file into sql server. Following is my jsp page form tag which calls a servlet which has the storage code..
<form name="form" action="NewServlet" method="POST" enctype="multipart/form-date">
<input type="file" name="file" size="20">
<input type="submit">
</form>
here is my servelt code for the same
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try{
String path= request.getParameter("file");
Connection con= null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:SQL","sa","mith1234");
File image = new File(path);
PreparedStatement ps = con.prepareStatement("insert into temp values(?)");
FileInputStream fis= new FileInputStream(image);
ps.setBinaryStream(1, (InputStream)fis, (int)(image.length()));
int s= ps.executeUpdate();
if(s>0)
{
out.println("Successfull");
}
else
{
out.println("unsuccessful");
}
}
catch(Exception e)
{
out.println(""+e);
}
out.close();
}
I think there is some problem in finding the correct path of the image am getting NullPointerException...