String [] Titulo = {
       “ID”,
      “ CDEP”,
      “ NOMDEP”,
       “ POB”
      }; //这是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



  而(Resultadobm.next()){
       //这是我不知道如何获取前两行的字符串或值的部分


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);

}

}

最佳答案

while(Resultadobm.next()){//这是我不知道的部分
  获取前两行的字符串或值


我不确定我是否理解正确,我认为您可以在获取前两行后终止循环:

while (Resultadobm.next() && Resultadobm.getRow() <= 2) {
  // ...your code
}

关于java - 如何从Access的表中获取前2条记录并将其添加到Jtable(数据过滤器),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42475278/

10-11 17:30