Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中将nvarchar(max)数据类型转换为字符串_Java_Sql_Sql Server 2008 - Fatal编程技术网

在Java中将nvarchar(max)数据类型转换为字符串

在Java中将nvarchar(max)数据类型转换为字符串,java,sql,sql-server-2008,Java,Sql,Sql Server 2008,我正在使用jTDS API在sql Server 2008上执行以下sql查询: SELECT a , b , c FROM [db].[dbo].[table] where d = 1; 这三个字段的数据类型如下: a -- nvarchar(255) b -- nvarchar(255) c -- nvarchar(max) 当我使用Java执行查询时,a和b的字符串值是纯文本,但对于c,我得到以下值: net.sourceforge.jtds.jdbc.ClobImpl@2b3

我正在使用jTDS API在sql Server 2008上执行以下sql查询:

SELECT  a , b , c FROM [db].[dbo].[table] where d = 1;
这三个字段的数据类型如下:

a  -- nvarchar(255)
b  -- nvarchar(255)
c  -- nvarchar(max)
当我使用Java执行查询时,a和b的字符串值是纯文本,但对于c,我得到以下值:

net.sourceforge.jtds.jdbc.ClobImpl@2b34fb

它似乎存储为object,如何将其转换为普通字符串?

尝试了@Roberto Navaron发送的链接,成功了,只是将object传递给此方法,将其键入cast to clob并返回字符串

private String clobToString(Clob data) {
    StringBuilder sb = new StringBuilder();
    try {
        Reader reader = data.getCharacterStream();
        BufferedReader br = new BufferedReader(reader);

        String line;
        while(null != (line = br.readLine())) {
            sb.append(line);
        }
        br.close();
    } catch (SQLException e) {
        // handle this exception
    } catch (IOException e) {
        // handle this exception
    }
    return sb.toString();
}
或者我们可以用这个-

  • 字符串getNString(int-columnIndex)
  • 字符串getNString(字符串列标签)

Java中的类型是什么?DBVT_字符串?DBVT_ASTRING?还有什么?当您从
结果集
获取值时,我认为您已经尝试了
getString(column)
getCharacterStream(column)
?DBVT\u STRING,即使我试过了,但还是一样。我想看看这个链接:找到这个,看看: