Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Null pointer exception in FileInputStream

843841Mar 3 2005 — edited Mar 9 2005
Hi All,

I get a java.lang.NullPointerException at the following code. I am trying to insert a blob object in a mysql database.

The java.lang.NullPointerException is in the FileInputStream fis = new FileInputStream(file);.
Can anyone tell me what is wrong.
 public void doPost(HttpServletRequest request, HttpServletResponse response) throws
      ServletException, IOException {
   
   
 String file = request.getParameter("file");  
 FileInputStream fis = new FileInputStream(file);
 
 
 try {
   Class.forName( "org.gjt.mm.mysql.Driver" );
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/osso", "root", "root");
 
          PreparedStatement pstmt = con.prepareStatement("INSERT INTO bestanden (Data) VALUES (?)");
          //  provide values for prepared statement and execute update
          pstmt.setString (1, "theName");
         // pump it in with a file input stream
          pstmt.setBinaryStream (2, fis, file.length());
          pstmt.executeUpdate();
          pstmt.close();
       } catch (Exception e) { e.printStackTrace(); }
 
 }
My JSP is as follows:
<html>
<head>
<title>
upload
</title>
</head>
<body bgcolor="#ffffff">
<form action="/upload" method="POST" name="upload" enctype="multipart/form-data" target="main">
  <input type="file" name="file" value="">
  <input type="hidden" name="actie" value="opslaan"/>
  <input type="submit" name="uploaden" value="Uploaden"/>
</form>
<form action="/upload" method="post" target="main">
  <input type="hidden" name="actie" value="ophalen"/>
  <input type="submit" name="ophalen" value="Bestand ophalen"/>
</form>
</body>
</html>
Any suggestions what I am doing wrong. Or have somebody another idea to load files up to mysql database.

Regards,

Henk
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 6 2005
Added on Mar 3 2005
16 comments
1,706 views