Now, I want to transfer my data in the network, my client maybe a Jsp/Servelt, or a Delphi client. So I should transfer my data in xml format.
But, I don't know how to transfer a ResultSet into Xml Object that can be read by Delphi client? I think i should provide a string stream in xml format? but i don't know how to solve it? sigh, there are too many tech about xml for me to select...
-
How to provide Xml Data for other client like VB,Asp in Ejb??? (3 messages)
- Posted by: Kadvin XJ
- Posted on: November 24 2002 08:26 EST
Threaded Messages (3)
- How to provide Xml Data for other client like VB,Asp in Ejb??? by Lasse Koskela on November 24 2002 10:13 EST
- How to provide Xml Data for other client like VB,Asp in Ejb??? by stephen smithstone on November 24 2002 10:49 EST
- How to provide Xml Data for other client like VB,Asp in Ejb??? by Leonard Gurevich on November 25 2002 17:29 EST
-
How to provide Xml Data for other client like VB,Asp in Ejb???[ Go to top ]
- Posted by: Lasse Koskela
- Posted on: November 24 2002 10:13 EST
- in response to Kadvin XJ
Here's a simple hack for generating XML from a ResultSet. It came from the top of my head and I haven't tested it in anyway, but I think it should work (for the basic numeric, alphanumeric and time-related SQL types).
/**
* Returns an XML representation of the given ResultSet.
*/
private String resultSetToXml(ResultSet rs)
{
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
int row = 0;
StringBuffer xml = new StringBuffer(1000);
xml.append("<?xml version=\"1.0\"?>");
xml.append("<resultset>");
while (rs.next())
{
row++;
xml.append("<row number=\"" + row + "\">");
for (int i=0; i < numberOfColumns; i++)
{
Object obj = rs.getObject(i);
xml.append("<column");
xml.append(" name=\"" + rsmd.getColumnName(i) + "\"");
xml.append(" type=\"" + obj.getClass().getName() + "\"");
xml.append(" value=\"" + obj.toString() + "\"");
xml.append("/>");
}
xml.append("</row>");
}
xml.append("</resultset>");
return xml.toString();
}
...and the resulting XML should look like this:
<?xml version="1.0"?>
<resultset>
<row number="1">
<column name="id" type="java.lang.Integer" value="123"/>
<column name="price" type="java.lang.Float" value="123.45"/>
<column name="timestamp" type="java.sql.Timestamp" value="2002-01-23 12:34:56.0"/>
</row>
<row number="2">
<column name="id" type="java.lang.Integer" value="456"/>
<column name="price" type="java.lang.Float" value="543.21"/>
<column name="timestamp" type="java.sql.Timestamp" value="2002-02-02 23:45:01.0"/>
</row>
...
</resultset> -
How to provide Xml Data for other client like VB,Asp in Ejb???[ Go to top ]
- Posted by: stephen smithstone
- Posted on: November 24 2002 10:49 EST
- in response to Kadvin XJ
another way to could do it is to use webservices and have other clients call the webservice and get the results from the method , as the overall meaning of webservices is to provide operatiblity between different programming languages -
How to provide Xml Data for other client like VB,Asp in Ejb???[ Go to top ]
- Posted by: Leonard Gurevich
- Posted on: November 25 2002 17:29 EST
- in response to Kadvin XJ
What about SUN's WebRowSet?