-
> I am tired of trying
You're tired of trying?
how do you think I feel? :rolleyes:
Assuming you can fit the whole blob into a single string, it's probably something like this:
Code:
<%Blob textBlob = RsQuestions.getBlob("QName");
String text = new String(textBlob.getBytes(1, (int)textBlob.length()));%>
<%=text %>
If you can't get it all into a single string (or if it comes out as junk):
Code:
try {
Blob blob = getBlob();
BufferedReader reader = new BufferedReader(
new InputStreamReader(RsQuestions.getBlob"QName").
getBinaryStream()));
String line = reader.readLine();
while (line != null) {
// Output line here: <%=line%>
line = reader.readLine();
}
}
catch(SQLException sqe) {
handleException(sqe);
}
catch (IOException ioe) {
handleException(ioe);
}
I'll leave you to turn it into JSP.
If you get junk text coming out, you'll need to pass a Charset to the InputStreamReader along with the BinaryStream, to do the conversion from the blob bytes to Java's UNICODE characters. For example, to convert from Seven-bit ASCII (ISO646-US) coded bytes, pass in Charset.forName("US-ASCII"). Likewise for the ISO Latin Alphabet No. 1, (ISO-LATIN-1), pass in Charset.forName("ISO-8859-1"). See Charset for details. Of course, it helps if you know what the character encoding of the bytes in the blob are in the first place!
Not tonight dear, I had a really tiring day at work today...
-
Thank you very much for your help. It's finally working, all thanks to you.
-
Excellent! success at last :D
A flea met a fly in a flue,
Said the flea 'let us fly',
Said the fly 'let us flee',
So they flew through a flaw in the flue...
-
I tried to use that code but I got this error:
java.lang.AbstractMethodError: org/gjt/mm/mysql/ResultSet.getBlob
here is the code, could you help me please?:
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*, java.io.*" errorPage="" %>
<%@ include file="../Connections/Mysql.jsp" %>
<%
Driver DriverBLOB1 = (Driver)Class.forName(MM_Mysql_DRIVER).newInstance();
Connection ConnBLOB1 = DriverManager.getConnection(MM_Mysql_STRING,MM_Mysql_USERNAME,MM_Mysql_PASSWORD);
PreparedStatement StatementBLOB1 = ConnBLOB1.prepareStatement("SELECT * FROM blob1");
ResultSet BLOB1 = StatementBLOB1.executeQuery();
boolean BLOB1_isEmpty = !BLOB1.next();
boolean BLOB1_hasData = !BLOB1_isEmpty;
Object BLOB1_data;
int BLOB1_numRows = 0;
%>
<HTML>
<BODY>
<%
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(BLOB1.getBlob("blob1").
getBinaryStream()));
String line = reader.readLine();
while (line != null) {
// Output line here: <%=line
line = reader.readLine();
}
}
catch(SQLException sqe) {
}
catch (IOException ioe) {
}%>
</BODY>
</HTML>
<%
BLOB1.close();
StatementBLOB1.close();
ConnBLOB1.close();
%>
-
I dunno... maybe your JDBC driver is obsolete and doesn't support the getBlob() method... If it's any earlier than Java 1.2, it won't.
4000 feet up, exposed on the south col, he was caught in the whirling nightmare of the blizzard...
-
you need to refer to your driver documentation for details on blob access; typically drivers dont provide BLOBs as objects like a whole String() anyway; they provide read/write access to them via input/output streams.. read your driver documentation
finally, may i ask why you are using a BLOB to store text, when a CLOB exists?