Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 DataTruncation while using "for xml raw" in Java

Author  Topic 

pskceo
Starting Member

1 Post

Posted - 2002-11-28 : 07:23:13
Hi people,

Problem faced : DataTruncation after 2033 Bytes.
Reason for prob: using "FOR XML RAW" in select statement
Driver Used : SQLServerDriver (2000)
JDBCDriver Type: Type 4
Tried : Getting SQLWarning Object from resultset but none exist
Methods Tried : getAsciiStream(),getCharacterStream(),getString(),
getBinaryStream(),getBytes(),getObject()
ColumnTypeName : ntext (SQLServer2000 DataType)

piece of code :
........
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Con = DriverManager.getConnection("jdbc:microsoft:sqlserver:.....");
........
........

stmt = Con.createStatement();
rs = stmt.executeQuery("select * from Test For xml raw");
rs.next();

ResultSetMetaData rsm = rs.getMetaData();
byte byteArray[]= new byte[5000];//fixing a limit >2033 bytes to test
ByteArrayOutputStream bos =null;
BufferedInputStream temp1 = new BufferedInputStream(rs.getAsciiStream(rsm.getColumnName(1)));
try{
bos= new ByteArrayOutputStream();
while(temp1.read(byteArray,0,byteArray.length)!=-1){
bos.write(byteArray,0,byteArray.length);
}
}catch(Exception e){e.printStackTrace();}
Con.close();

System.out.println("ColumnTypeName "+rsm.getColumnTypeName(1));
System.out.println(bos.toString()); //copy&paste this String 2033bytes
}
catch(Exception e)
{
e.printStackTrace();
}
Because of this I could not make use of the SQLServer200 feature of getting resultset as xml instead am building xml from the resultset.!
Do any one of you have a solution please do reply to this query ASAP.
Thanks in Advance...!


   

- Advertisement -