I code below class to store the image in a database but not getting result..exception : NullPointerException why???
package src;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class StorePhoto extends HttpServlet
{
public void init(ServletConfig s) throws ServletException
{
super.init(s);
System.out.println("Servlet Initiated");
}
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException
{
doPost(req,res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:adsn");
Statement stmt = con.createStatement();
System.out.println("connection created");
HttpSession session = req.getSession();
String url = req.getParameter("path");//here path is the parameter coming from html page...
System.out.println("URL = "+url);
System.out.println("session ID ="+session.getId());
PreparedStatement pst = con.prepareStatement("insert into image(photo) values(?)");
System.out.println("query executed");
FileInputStream fis = new FileInputStream(url);
System.out.println("FIS object created");
byte[] b = new byte[fis.available()+1];
fis.read(b);
pst.setBytes(1,b);
pst.executeUpdate();
System.out.println("query exccuted and update done");
pst.close();
con.close();
}
catch(SQLException e)
{
System.out.println("SQL exception");
e.printStackTrace();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
}
}