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).
在一个javascript应用程序中,我们在SQL Server 2005上调用一个sproc,它返回一个带有3列类型的结果集:bigint,varchar(20)和varchar(MAX)。
When calling the sproc and reading the results, there's no exception being thrown. When enumerating the resultset:
在调用sproc并读取结果时,不会抛出任何异常。枚举结果集时:
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:
在检查myString的值时,该值不是我所期望的:
javax.sql.rowset.serial.SerialClob@15b4206
Any idea how to get the real value of the field?
知道如何获得该领域的真正价值吗?
Calling another method other than getString() maybe?
调用getString()以外的其他方法可能吗?
1 个解决方案
#1
Varchar(MAX) is a CLOB (Character Large Object) data type. Here's some code you can use in order read its contents.
Varchar(MAX)是CLOB(字符大对象)数据类型。以下是您可以使用的一些代码,以便阅读其内容。
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();
#1
Varchar(MAX) is a CLOB (Character Large Object) data type. Here's some code you can use in order read its contents.
Varchar(MAX)是CLOB(字符大对象)数据类型。以下是您可以使用的一些代码,以便阅读其内容。
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();