Re: Getting FOR XML into Java
- From: "David Browne" <davidbaxterbrowne no potted meat@xxxxxxxxxxx>
- Date: Sat, 25 Feb 2006 07:39:05 -0600
<spjo55@xxxxxxxxx> wrote in message
news:1140830038.866049.255580@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello there
I have a question regarding the XML support in SQL Server 2005 and the
new Microsoft JDBC driver. I hope to get XML from SQL Server to do
XSLT-processing at the web-tier, but lack some sample code of how get
XML through JDBC when I do a SELECT .... FOR XML.
In this article
http://www.windowsitpro.com/Article/ArticleID/22324/22324.html Rich
Rollman describes a "character-encoding mismatch between SQL Server
and Java" and suggests this code:
// Display the SQL results.
while(rs.next())
{
InputStream is = rs.getBinaryStream(1);
InputStreamReader isr = new
InputStreamReader(is,"UnicodeLittle");
while ((c = isr.read()) != -1)
{
bw.write(c);
sb.append((char) c);
}
}
The article/code above is from 2001, and my question is how best to
tackle this with SQL Server 2005 and the new driver. I can do it by
building a String in the while loop, but I think that there might be a
better way.
Eventually I will need to pass the XML as a javax.xml.transform.Source
to do the transformation.
I'm not sure what the best way is, but with SQL 2005 you can easilly get the
XML as a string. EG
declare @xml xml
select (select * from sys.objects for xml auto, type)
select cast(@xml as varchar(max)) xml
David
.
- Follow-Ups:
- Re: Getting FOR XML into Java
- From: spjo55
- Re: Getting FOR XML into Java
- References:
- Getting FOR XML into Java
- From: spjo55
- Getting FOR XML into Java
- Prev by Date: Re: Callablestatement.execute() and clearParameter() causing excep
- Next by Date: Re: execute() vs executeUpdate() on a prepared statement
- Previous by thread: Getting FOR XML into Java
- Next by thread: Re: Getting FOR XML into Java
- Index(es):
Relevant Pages
|
Loading