i am trying to upload the image file onto the server. for that created a table and a field of BLOB. now i am trying to upload the image into database. but i am getting a null pointer exception. here is the servlet LITS_bin bin = new LITS_bin();
bin.setProduct_name(request.getParameter("productName"));
bin.setPrice(Integer.parseInt(request.getParameter("price")));
String strpath = request.getParameter("txtFileName");
System.out.println(strpath+bin.getProduct_name()+bin.getPrice());
String filepath=strpath.substring(strpath.lastIndexOf("//")+1);
System.out.println(filepath);
File imgfile = new File(strpath);
FileInputStream fin;
try
{
fin = new FileInputStream(imgfile);
LITSdatabaseConnection.doConnection();
String sql = "insert into product (product_name,price,image)values ?,?,?";
PreparedStatement pst = LITSdatabaseConnection.getCon().prepareStatement(sql);
pst.setString(1, bin.getProduct_name());
pst.setFloat(2, bin.getPrice());
pst.setBinaryStream(3, fin,imgfile.length());
int i = pst.executeUpdate();
System.out.println(i+"Record Inserted"+bin);
}
catch (FileNotFoundException fil)
{
fil.printStackTrace();
System.out.println(fil);
}
catch (SQLException e)
{
//System.out.println(e);
e.printStackTrace();
}