wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes How to know no of records  resultset contains in xml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to know no of records  resultset contains in xml file" Watch "How to know no of records  resultset contains in xml file" New topic
Author

How to know no of records resultset contains in xml file

Anil Subudhi
Greenhorn

Joined: Apr 26, 2011
Posts: 10
How to get no of record counts in xml file from resultset.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
Exactly how is a resultset getting turned into an XML file?

Are you able to parse the xml file into a DOM?

Bill
Anil Subudhi
Greenhorn

Joined: Apr 26, 2011
Posts: 10
hi,
i want to retrieve multiple records from database using resultset in xml file.Is there any way to get no of records present from db in xml file. My requirement is below red color x value i set to manually but i need it will set using auto return value by some function or any other way in xml file.
------------------------------------------------------------

<?xml version="1.0"?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd"
xmlns:db="http://www.milyn.org/xsd/smooks/db-routing-1.1.xsd"
xmlns:jb="http://www.milyn.org/xsd/smooks/javabean-1.2.xsd"
xmlns:ds="http://www.milyn.org/xsd/smooks/datasource-1.1.xsd">

<ds:direct bindOnElement="#document" datasource="DB" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/dbase" username="root" password="praya123" autoCommit="false" />
<db:executor executeOnElement="Invoice" datasource="DB" executeBefore="true">
<db:statement>SELECT * FROM custinfo</db:statement>
<db:resultSet name="rs_custinfo" />
</db:executor>
<db:executor executeOnElement="Invoice" datasource="DB" executeBefore="true">
<db:statement>select * from callRates</db:statement>
<db:resultSet name="rs_callRates" />
</db:executor>
<db:executor executeOnElement="Invoice" datasource="DB" executeBefore="true">
<db:statement>select * from InvoiceSummary</db:statement>
<db:resultSet name="rs_InvoiceSummary" />
</db:executor>
<db:executor executeOnElement="Invoice" datasource="DB" executeBefore="true">
<db:statement>select * from InvoiceDetail</db:statement>
<db:resultSet name="rs_InvoiceDetail" />
</db:executor>

<ftl:freemarker applyOnElement="Invoice">
<ftl:template>

<!--
<#assign x=1>
<#list 1..x as i>


<DETAIL>
<DT_INV_HDR1>${rs_custinfo[i].BillingAccNo}</DT_INV_HDR1>
<DT_INV_HDR2>${rs_custinfo[i].CustNo}</DT_INV_HDR2>
<DT_INV_HDR3>${rs_custinfo[i].InvoiceNo}</DT_INV_HDR3>
<DT_INV_HDR4>${rs_custinfo[i].InvoiceDate}</DT_INV_HDR4>
<DT_INV_HDR5>${rs_custinfo[i].PaymentDueDate}</DT_INV_HDR5>
<DT_INV_HDR6/>
<DT_INV_HDR7/>
</DETAIL>

</#list>

-->

</ftl:template>
</ftl:freemarker>
</smooks-resource-list>
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
Your use of the "smooks" tools means I have not the faintest idea what is going on and I'm not about to spend any time on yet another toolkit.

Surely there is a smooks mailing list or users group that could handle the question.

Bill
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

There's no way to get the number of records that will be available from a ResultSet using regular Java. The standard way is to read the records and count them as you go along.

To put it another way, modelling a ResultSet as an array is folly. You should model it as a List. Perhaps you can do that in this XML-based language; that would be your most practical approach if you are indeed forced to use a ResultSet. However the standard way to do this sort of thing is to read all of the ResultSet rows into a List of objects in the model tier, and then process that List in the view tier. That's true even if the language used for the view tier allows you to process ResultSets.

Although it strikes me that if this tool does indeed allow you to process ResultSets, it must therefore allow you to read through the records. And since it isn't possible to know in advance the number of records, and the designers surely would have known that, it must allow you to read through the records without knowing how many there will be. Are there no examples and tutorials available?
Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 89
Hi.


I have been working with some xml and Java recently and I'd just like to add that in my situation, I was using Oracle also and it might be worth checking if your database can generate the xml with the row numbers as an xml attribute - certainly Oracle can produce an xml file with this embedded in it. However, as the previous post suggested, alternatively, count each record as they are output.

Colm
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to know no of records resultset contains in xml file
 
Similar Threads
Converting resultset into hierarchical XML
Database to XML convertion
ResultSet into XML-File ?
how to create jrxml format of Jasperreport at runtime?
My Data over The network