2012-08-13 90 views
3

我执行下面的SQL Server上的SQL查询2008年使用JTDS API:转换为nvarchar(max)数据类型为字符串的Java

SELECT a , b , c FROM [db].[dbo].[table] where d = 1; 

而对于这三个字段的数据类型如下:

a -- nvarchar(255) 
b -- nvarchar(255) 
c -- nvarchar(max) 

当我使用Java,A和b的字符串值执行查询是纯文本,但对于C我得到以下值:

[email protected] 

它似乎存储为对象,我如何将它转换为普通字符串?

+0

Java中的类型是什么? DBVT_STRING? DBVT_ASTRING?还有别的吗? – 2012-08-13 20:52:24

+1

当你从ResultSet中取得值时,我已经尝试了'getString(column)'和'getCharacterStream(column)'? – 2012-08-13 20:53:54

+0

是试过了,还是一样的 – Pradeep 2012-08-13 20:58:20

回答

5

试图通过@Roberto Navaron发来的链接,它的工作,只是传递的对象,以这种方法,类型将它转换为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(); 
} 
相关问题