Hello everybody. I've landed into a serious problem. I have to upload images/videos in Oracle 9i database and I also have to device some mechanism through which I could view them later. I've got some codes which did not solve my problem. I'm posting the codes along with the structure of the oracle table here. Please suggest me something to solve this problem. PLEASE please please help me out
My Oracle 9i table structure is:
Name of the table is IMAGEMAIN
Id: number(3)
Image: BLOB
I've a html file named "index.html". Its contents are:
HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="index.jsp">
<input type="text" name="hint">
<br><input type="file" name="user_file">
<br> <input type="SUBMIT" name="s1" value="Save">
</form>
</body>
</html>
"index.jsp" page is there to upload the BLOB into database:
<%@ page import = "java.sql.*"%>
<%@ page import = "java.io.*,java.util.*,javax.servlet.*,javax.servlet.http.*" %>
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<h1>Insert into Oracle9i!</h1>
<%
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oracle9i","scott","tiger");
String ll=request.getParameter("user_file");
String lo=request.getParameter("hint");
File imgfile = new File(ll);
FileInputStream fin = new FileInputStream(imgfile);
PreparedStatement pre = con.prepareStatement("insert into IMAGEMAIN (id,image) values(?,?)");
pre.setString(1,lo);
pre.setBinaryStream(2,fin,(int)imgfile.length());
pre.executeUpdate();
pre.close();
}catch(Exception E){ out.println("the error is "+ E);}
%>
</body>
</html>
And "view.jsp" to view the BLOBs in tha database:
<%@ page language = "java" import="java.sql.*,java.io.*,java.util.*,javax.servlet.*,javax.servlet.http.*, oracle.sql.BLOB" %>
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<h1>Retrieve from Oracle9i!</h1>
<%
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oracle9i","scott","tiger");
Statement st1=con.createStatement();
ResultSet rs1 = st1.executeQuery("select image from IMAGEMAIN where id='1'");
String imgLen="";
if(rs1.next()){
imgLen = rs1.getString(1);
out.println(imgLen.length());
}
rs1 = st1.executeQuery("select image from IMAGEMAIN where id='1'");
if(rs1.next()){
int len = imgLen.length();
byte [] rb = new byte[len];
InputStream readImg = rs1.getBinaryStream(1);
int index=readImg.read(rb, 0, len);
System.out.println("index"+index);
st1.close();
response.reset();
response.setContentType("image/jpg/gif");
response.getOutputStream().write(rb,0,len);
response.getOutputStream().flush();
}
}catch(Exception E){E.printStackTrace();}
%>
</body>
</html>
I get absolutely blank index.jsp and view.jsp pages. Only the heading part within the <h1> is visible. Please suggest me something!