views:

680

answers:

1

Within a javascript app, we're calling a sproc on SQL Server 2005 that's returning a resultset with 3 columns of type: bigint, varchar(20), and varchar(MAX).

When calling the sproc and reading the results, there's no exception being thrown. When enumerating the resultset:

var dbConn = DatabaseConnectionFactory.createDatabaseConnection("1","2","3","4");    
var myResultSet = dbConn.executeCachedQuery("EXEC MySproc");
dbConn.close();

var myString = myResultSet.getString("MyVarcharMaxField");

When examining the value of myString, the value is not what I expect:

javax.sql.rowset.serial.SerialClob@15b4206

Any idea how to get the real value of the field?

Calling another method other than getString() maybe?

+1  A: 

Varchar(MAX) is a CLOB (Character Large Object) data type. Here's some code you can use in order read its contents.

var clobField = myResultSet.getClob("MyVarcharMaxField");
var strOut = new java.lang.StringBuffer();
var aux = new java.lang.String();

// RTF data conversion

var kit = new Packages.javax.swing.text.rtf.RTFEditorKit();
var doc = new Packages.javax.swing.text.DefaultStyledDocument();
kit.read(clobField.getAsciiStream(), doc, 0);

var text = doc.getText(0, doc.getLength());
var myString = text.toString();
Jose Basilio