Skip to content Skip to sidebar Skip to footer

Converting Nvarchar(max) Data Type To String In Java

I am executing following sql query on SQL Server 2008 using jTDS API: SELECT a , b , c FROM [db].[dbo].[table] where d = 1; And data type for these three fields are as follows: a

Solution 1:

Tried the Link Sent by @Roberto Navaron , It worked, just passed object to this method, type cast it to clob and it returns string

private String clobToString(Clob data) {
    StringBuildersb=newStringBuilder();
    try {
        Readerreader= data.getCharacterStream();
        BufferedReaderbr=newBufferedReader(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();
}

Solution 2:

Or we can use this -

  • String getNString(int columnIndex)
  • String getNString(String columnLabel)

http://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html

Post a Comment for "Converting Nvarchar(max) Data Type To String In Java"