jdbc-obdc resultset returning more than expected

Hi,

Need Help,

Here is the thing,I have a table on an acces DB with 3k rows, in order to use it efficiently every query is topped just like the one below.

select top 100 catclientes.codigo,catclientes.nombre,catclientes.rfc,catclientes.calle,catclientes.numero,catclientes.codcolonia,catclientes.comercial,catclientes.telefono,catclientes.direccion,catclientes.estado,catclientes.pais,catclientes.comentarios,catclientes.fax,catclientes.email,catclientes.curp,catclientes.contacto,catcolonia.cp,catcolonia.colonia,catcolonia.tipo,catcolonia.ciudad,catcolonia.zona from catclientes left join catcolonia on catclientes.codcolonia=catcolonia.codigo where catclientes.codigo LIKE '%' and catclientes.nombre LIKE '%' and catclientes.rfc LIKE '%' and catclientes.eliminado=false

after executing the query, I try to fit the resultset into a table, the process works like a charm while the table population is below 100, but once the table has more than that the resultset fetches more than that....

here is the process I use:

publicstatic javax.swing.JTable getTableFromRS(java.sql.ResultSet RS,int limitcolumns){

javax.swing.JTable Table=new javax.swing.JTable();

try{

java.sql.ResultSetMetaData RSMD = RS.getMetaData();

RS.last();

int jx=RS.getRow();

if(limitcolumns==0||limitcolumns>RSMD.getColumnCount()){

limitcolumns=RSMD.getColumnCount();

}

String[] Nombres =new String[limitcolumns];

for(int i=1;i<=limitcolumns;i++){

Nombres[i-1] = RSMD.getColumnName(i).toUpperCase();

}

String[][] Objeto =new String [jx][limitcolumns];

int j=0;

RS.beforeFirst();

while (RS.next()){

for(int i=1;i<=limitcolumns;i++){

Objeto[j][i-1]=RS.getString(i);

}

j++;

}

finalboolean[] canEdit =newboolean[limitcolumns];

for(int i=0;i<canEdit.length;i++){

canEdit[i]=false;

}

Table.setBorder(new javax.swing.border.TitledBorder(""));

Table.setModel(new javax.swing.table.DefaultTableModel(

Objeto,

Nombres

){

publicboolean isCellEditable(int rowIndex,int columnIndex){

return canEdit [columnIndex];

}

});

}catch(java.sql.SQLException e){

System.out.println(e+" ><etool.line226>");

e.printStackTrace();

}

return Table;

}

on the last debug run the jx temp variable got a > 3000 value when it was supposed to have 100.

Am I wrong or anyone knows a way to fix this without changing the query? (that is if the query itself is formulated without errors)

[4250 byte] By [el_residentea] at [2007-11-27 3:07:19]
# 1
which database are you using ?see this for more details (last table): http://en.wikipedia.org/wiki/Select_(SQL)
java_2006a at 2007-7-12 3:54:21 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
I'm using a MS-Access DB
el_residentea at 2007-7-12 3:54:21 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

Because MS Access database has got some limitations which we can not choose a limited data rows from complete database table. Of couse if you using SQL server, there is no any limitations.

This is correct version which display only 100 records :

select top 100 * from(select * from mytable)

Take a look at ROW_NUMBER() window function in the article I previously posted.

Hope That Helps

java_2006a at 2007-7-12 3:54:21 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

Thanks for the response...

This query, does gives back what I want, but only from access, the resultset still has the problem.....

now i made a fix to the program limiting from my end the resultset.

I already tried the row_number() window function but it is not recognized by access..

may there be a way to fix this on the jdbc-odbc bridge....?

el_residentea at 2007-7-12 3:54:21 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

>may there be a way to fix this on the jdbc-odbc bridge....?

I dont think so.

Try a simple select query example that uses TOP and only one field.

example:

SELECT TOP 10 your_table.colID FROM your_table

(I think the problem comes from your select query )

java_2006a at 2007-7-12 3:54:21 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6
I' give it a try....
el_residentea at 2007-7-12 3:54:21 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...