cancel
Showing results for 
Search instead for 
Did you mean: 

How to get a query row count

0 Kudos

Hi there,

I'm trying to get the query row count from the rs array of the following xsjs code:


var conn = $.db.getConnection();

var pstmt = conn.prepareStatement( "select * from DUMMY" );

var rs = pstmt.executeQuery();

Is there a property or method to call and get the row count? Something like rs.length or rs.size.

Thanks a lot!

Alejandro Fonseca.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

I don't think there is a property or method to get the row count. You can find the API here.

JSDoc: Class: ResultSet

JSDoc: Class: ResultSetMetaData

Best regards,

Wenjun

0 Kudos

Hi Wenjun,

Apparently, there is no such a method. I'm gonna have to create an array and then do a loop to fetch the data from it in order to organise the contents as I need.

Cheers.

Alejandro.

Former Member
0 Kudos

Or send SELECT COUNT(COLUMN) as a separate request. That will provide the functionality you need, would it not?

0 Kudos

Hi John,

The trouble is that the query wasn't as simple as selecting data from a single column, but many columns and tables with joins included.

I've finally solved it in JavaScript on the client side.

Thanks though.

Alejandro.

Former Member
0 Kudos

Well in my case here,s what I did

I used a select statement

var ID=1;// set to 1 because in needed to use it for the next ID , this is not safe but just for fun

var conn = $.db.getConnection();

conn.prepareStatement("SET SCHEMA \"SYSTEM\"").execute();

//get ID

var pstmt = conn.prepareStatement(

  "select * from \"SYSTEM\".\"MYTABLE\""

);

var rs = pstmt.executeQuery();

if(!rs.next())

  {

  body = "Failed Reteiving  attribute view";

  $.response.addBody(body); 

  }

else{

  while (rs.next())

  {

  ID++;

  }

}

.......

So you the ID value you can print out by attaching to a body tag or however you deem fit

the above code was done on a Severside .xsjs file

Answers (0)