You're correct. The code to generate a ByteArray was written after alpha
3. To use a ByteArray, change row.setColumnValues(ResultSet, Table,
boolean) to the following. The code has been lightly tested.
-- Ron
Row.setColumnValues(ResultSet, Table, boolean):
/**
* Set column values from a result set
*
* @param rs The result set.
* @param table The Table object describing the rows in the result
set
* @param emptyStringIsNull Whether to treat empty strings as NULLs
*/
public void setColumnValues(ResultSet rs, Table table, boolean
emptyStringIsNull)
throws SQLException
{
Column[] rsColumns;
Column column;
Object o;
// Loop through the columns in the result set and set the
corresponding
// values in the Row. We use Table.getResultSetColumns() since
this:
// (a) Retrieves only the necessary columns (the result set might
have more), and
// (b) Retrieves the columns in ascending order, which is needed
for interoperability.
rsColumns = table.getResultSetColumns();
for (int i = 0; i < rsColumns.length; i++)
{
// Get the next column value.
column = rsColumns[i];
o = rs.getObject(column.getResultSetIndex());
// If the column value is NULL, set it to an EMPTYSTRING or
null.
if (rs.wasNull())
{
o = (emptyStringIsNull) ? EMPTYSTRING : null;
}
else if (o instanceof InputStream)
{
// If the returned object is an InputStream, then the
underlying column
// is probably a BLOB (LONGVARCHAR or LONGVARBINARY).
InputStream in = (InputStream)o;
ByteArrayOutputStream out = new ByteArrayOutputStream();
// Read the byte stream into a buffer.
int len;
byte[] buf = new byte[4096];
try
{
while ((len = in.read(buf)) != -1)
{
out.write(buf);
}
}
catch (IOException e)
{
throw new SQLException("[XML-DBMS] IOException. " +
e.getMessage());
}
// Convert the byte stream to a String (character data) or a
ByteArray
// (binary data). If the data type is none of these, throw
an exception,
// since JDBC doesn't define conversions between binary data
and other
// kinds of data.
int type = column.getType();
if (JDBCTypes.typeIsChar(type))
{
o = out.toString();
}
else if (JDBCTypes.typeIsBinary(type))
{
o = new ByteArray(out.toByteArray());
}
else
throw new SQLException("[XML-DBMS] The driver returned
data for the " + column.getName() + " column as an InputStream. JDBC
does not support conversions from stream (byte) data to " +
JDBCTypes.getName(type) + ".");
}
// Set the column value.
setColumnValue(column, o);
}
}
uwez2004 wrote:
>
> oops...
> i found the Base64Formatter.java in sourceforge, and now i know that
> parse() and format() mothods have to be completed.
> But i schould have got the error message: "Method not yet
> implemented."
> instead of the one i got.
> Why xml-dbms, does not call format(Object o) with a proper Object of
> ByteArray?
> As far as i understand that, this problem does lay somewhere else.
> (But where?)
>
> thanks for reply
> Uwe
>
> --- In xml-dbms@yahoogroups.com, "uwez2004" <zietzling@g...> wrote:
> >
> > Hello!
> >
> > i try to read a blob column into xml.
> > I add'ed the following Line into the Options- section in the map
> File:
> > <FormatClass
> >
> Class="org.xmlmiddleware.conversions.formatters.external.Base64Formatt
> > er DefaultForTypes="BINARY VARBINARY LONGVARBINARY" />"
> >
> > and the declared the column as folows in Tacle Section:
> >
> > <Column Name="aufgabe" DataType="LONGVARBINARY" Nullable="Yes"/>
> >
> > It throws the following Exception:
> >
> > java.sql.SQLException: [XML-DBMS] Conversion error: Object must be
> an
> > org.xmlmiddleware.conversions.ByteArray.
> > at org.xmlmiddleware.xmldbms.DBMSToDOM.getStringValue
> > (DBMSToDOM.java:1057)
> > at org.xmlmiddleware.xmldbms.DBMSToDOM.processColumn
> > (DBMSToDOM.java:455)
> > ........and so on.
> >
> >
> > You wrote, that we have to implement the parse(), an format()
> methods
> > of the Base64Formatter class. But to me, it looks like this is
> > allready done in xmldbms20.jar. (?)
> >
> > couldt you give me some advice?
> > thx in advance
> > Uwe