2009/6/7 Nuno Magalhães <[email protected]>: > Greetings, > > I'm using SQLite for an academic project, through Java's JDBC > (sqlitejdbc-0.5.4.jar). After executing a simple select, i can iterate > the ResultSet all the way (showing to output), no problem. The > problem, which may be silly, is that i need to get a row count so i > can initialize a variable. > > I tried using rs.getFetchSize() but it returns 0. This is the only > method i could relate to "getting number of rows" from the method > list. > > I tried rs.last(); but get "SQLException: ResultSet is > TYPE_FORWARD_ONLY" and wouldn't be able to get back anyway. > > I tried iterating the set and using rs.isLast() but i get > "SQLException: function not yet implemented for SQLite". > > I know this si more related to JDBC than SQLite, but maybe someone can > give me a hint?
Either run a SELECT Count(*) prior to running your full select query, or run the SELECT query, iterate over it counting the records, find the total number in the set, and then iterate over it and display as you are doing now. Either way, you would have to do a two-pass. I would prefer the two SELECTs, once for the Count() and second time for the query, for small results sets ... keep in mind, SELECT Count() in SQLite is not optimized. For big result sets, I might want to just do one mongo select and then count the results in memory. > > TIA, > Nuno Magalhães > > -- > () ascii ribbon campaign - against html e-mail > /\ ascii-rubanda kampajno - kontraŭ html-a retpoŝto > _______________________________________________ > sqlite-users mailing list > [email protected] > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > -- Puneet Kishor http://www.punkish.org/ Carbon Model http://carbonmodel.org/ Charter Member, Open Source Geospatial Foundation http://www.osgeo.org/ Science Commons Fellow, Geospatial Data http://sciencecommons.org Nelson Institute, UW-Madison http://www.nelson.wisc.edu/ ----------------------------------------------------------------------- collaborate, communicate, compete ======================================================================= Sent from Madison, WI, United States _______________________________________________ sqlite-users mailing list [email protected] http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

