Master Bitco 05 Master Bitco 05 -4 years ago 63
Java Question

How to get the first 2 records from Access's Table and Add them to Jtable (Data filter)


String[] Titulo = {
"ID",
"CDEP",
"NOMDEP",
"POB"
}; //This is the head of the Jtable


Mnc2 = new DefaultTableModel(null, Titulo);
String[] Filas = new String[4];

try { //HERE IS THE CONECTION TO THE BDD(ACCESS)
Conexion_DDB Conn = new Conexion_DDB();

//Prepared Query
PreparedStatement Consulta = Conn.getConnection().prepareStatement("SELECT * FROM [DEPARTAMENTOS]");
ResultSet Resultadobm = Consulta.executeQuery();

while (Resultadobm.next()) {
//This is the part thath I don't know how to get the Strings or values for each row
Filas[0] = Resultadobm.getString("CDEPID");
Filas[1] = Resultadobm.getString("CDEP");
Filas[2] = Resultadobm.getString("POBDEP");
Filas[3] = Resultadobm.getString("NOMDEP");

//There are more records but just for example



while (Resultadobm.next()) {
//This is the part thath I don't know how to get the Strings or values for the first two rows


Mnc2.addColumn(Filas);//Add the columns
}
/*At this part, I'm trying to get the values equals or higher than 50,000 to show then in the same table at the same time with the two first records found*/

//If you can help me here too I would appreciate it a lot

int Menora = 50000;
if (Mnc2.getValueAt(1, 1).equals(Menora)) {
Tabla_Busquedas.setValueAt(Mnc2, 1, 1);
}

Conn.Desconexion(); //Close the connection
} catch (SQLException ex) {
Logger.getLogger(Form_Tabla.class.getName()).log(Level.SEVERE, null, ex);

}

}

Answer Source

while (Resultadobm.next()) { //This is the part thath I don't know how to get the Strings or values for the first two rows

I am not sure I understand right.I think you can terminate the loop after you fetched first two rows:

while (Resultadobm.next() && Resultadobm.getRow() <= 2) { 
  // ...your code
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download