1 Reply Latest reply on May 4, 2007 7:38 AM by masijade

    File Upload to MYSQL Database

    807606
      hi.
      im very new to Java. Concepts...........anyone pls help me..
      i tried to upload text file in database butafter running.its displaying getting java.lang.NullPointerException ... i hv copied my code here..

      <%@ page import="java.sql.*"%>
      <%@ page import="java.io.*"%>
      <%@ page import="java.util.*"%>
      <!DOCTYPE html PUBLIC /"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title></title>
      </head>
      <body>
      <%
      try
      {
      String name=null;
      String address=null;
      String path=null;
      String filename;
      name=request.getParameter("name");
      address=request.getParameter("address");
      path = request.getParameter("content");
           //out.println(name);
           //out.println(path);
      File txt= new File(request.getParameter("content"));
      filename=txt.getName();
           //out.println(filename);
      {
           String databaseDriver = "com.mysql.jdbc.Driver";
           Class.forName( databaseDriver );
      String databaseName = "jdbc:mysql://localhost:3306/sushikha";
           Connection con=null ;
      con = DriverManager.getConnection(databaseName, "root","root");
      String str = "INSERT INTO db2 (name,address,path,data) VALUES (?,?,?,?)";
      PreparedStatement pstmt = con.prepareStatement(str);
      FileInputStream is = new FileInputStream(path);
           //out.println(path);
           //out.println(is);
           
           pstmt.setString(1, name);
           pstmt.setString(2, address);
           pstmt.setString(3, path);
      pstmt.setBinaryStream(4, is,(int) txt.length());
      pstmt.executeUpdate();
      }
      }
      catch(Exception e)
      {
      out.println(e);
      }

      %>

      </body>
      </html>































































      pls help me...