Click to See Complete Forum and Search --> : retrieving data from BLOB


jass
June 21st, 2004, 08:27 AM
Hello to everyone. First of all, I'm definitely new to a programming world. Thanks in advance for helping me.

I'm trying to retrieve a data (type =text) from a BLOB column by using java code in JSP. I got an internal error () . There is no error in the coding but I'm not sure if the code is working or not.

The internal error is;
java.lang.UnsupportedOperationException
at sun.jdbc.odbc.JdbcOdbcResultSet.getBlob(JdbcOdbcResultSet.java:4417)


Following is my full coding code:
<%@ page contentType="text/html; charset=iso-8859-1"
language="java" import="java.sql.*, java.io.*" %>

<%
// DB connection to ARCDOC
java.sql.Connection con;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:arcdoc","myusername","mypassword");


// SQL statement (Query 1)
String query = "select T_DORIS from arcdoc.provenance where DORIS_KEY = '762'";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);




boolean rs_isEmpty = !rs.next();
boolean rs_hasData = !rs_isEmpty;
Object rs_data;
int rs_numRows = 0;

%>

<HTML>
<BODY>
<%

try {

BufferedReader reader = new BufferedReader(new InputStreamReader(rs.getBlob("T_DORIS").getBinaryStream()));
String line = reader.readLine();
while (line != null) {

line = reader.readLine();
%>

<%=line %>

<%
}
} catch(SQLException sqe) {

} catch (IOException ioe) {

} finally {

rs.close();
stmt.close();
con.close();

}

%>
</BODY>
</HTML>


If there any better or much more flexible way of obtaining the data, please let me know. Can e-mail me personally for discussion as well (freda_henry@yahoo.com)

cjard
June 21st, 2004, 10:11 AM
it looks like the jdbc-odbc bridge does not support blobs in this manner; obtain a better database driver, probably along with a better database (e.g. mySQL) and read the driver documentation about BLOBs.. things are not always as you would expect

jass
June 21st, 2004, 10:50 AM
Yeah, I guess I should obtain oracle-JDBC. Unfortunately I can't use other db. Have to solve this problem. Will see if it works well after changing the driver.

cjard
June 21st, 2004, 11:15 AM
ps; have you tried ResultSet.getBinaryStream(int column_number) ?