By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,258 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,258 IT Pros & Developers. It's quick & easy.

How to store image in database using JSP

selvasoft
P: 34
Please any one help me i want store my image to oracle database am using JSP here is my code.But this code will return Null Pointer Error.
What is wrong with this code. Am using HTML form to browse and upload image.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <%@ page import="java.io.*,javax.servlet.http.HttpServletRequest,javax.servlet.ServletInputStream" %>  
  4. <%@ page import="java.io.FileWriter,java.io.IOException" %>  
  5. <%@ page import ="java.sql.*,java.io.*,java.util.*" %>
  6. <%
  7. String name=request.getParameter("fname");
  8. %>
  9. <%
  10.     String DomainName ="jdbc:oracle:thin:@192.168.251.28:1521:ms";
  11.         String UserName="sss";
  12.         String PassWord="xxx";
  13.  
  14. try
  15. {
  16.  
  17.           Class.forName("oracle.jdbc.OracleDriver");
  18.                   Connection cn=DriverManager.getConnection(DomainName,UserName,PassWord);
  19.           PreparedStatement pst = cn.prepareStatement("insert into image(simage) values(?)");
  20.           FileInputStream fis=new FileInputStream(name );
  21.  
  22.  
  23.           byte[] b= new byte[fis.available()+1];
  24.  
  25.           fis.read(b);
  26.           pst.setBytes(1,b);
  27.           pst.executeUpdate();
  28.           pst.close();
  29.           cn.close();
  30. }
  31.  
  32. catch(Exception e)
  33. {
  34.  
  35. System.out.println(e);
  36. }
  37.  
  38. %>
  39. </body>
  40. hai
  41. </html>
Mar 22 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.