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.
What is wrong with this code. Am using HTML form to browse and upload image.
Code:
<html>
<body>
<%@ page import="java.io.*,javax.servlet.http.HttpServletRequest,javax.servlet.ServletInputStream" %>
<%@ page import="java.io.FileWriter,java.io.IOException" %>
<%@ page import ="java.sql.*,java.io.*,java.util.*" %>
<%
String name=request.getParameter("fname");
%>
<%
String DomainName ="jdbc:oracle:thin:@192.168.251.28:1521:ms";
String UserName="sss";
String PassWord="xxx";
try
{
Class.forName("oracle.jdbc.OracleDriver");
Connection cn=DriverManager.getConnection(DomainName,UserName,PassWord);
PreparedStatement pst = cn.prepareStatement("insert into image(simage) values(?)");
FileInputStream fis=new FileInputStream(name );
byte[] b= new byte[fis.available()+1];
fis.read(b);
pst.setBytes(1,b);
pst.executeUpdate();
pst.close();
cn.close();
}
catch(Exception e)
{
System.out.println(e);
}
%>
</body>
hai
</html>