gpt4 book ai didi

java - 如何从Access的表中获取前2条记录并将它们添加到Jtable(数据过滤器)

转载 作者:太空宇宙 更新时间:2023-11-04 11:44:19 25 4
gpt4 key购买 nike

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

}

}

最佳答案

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

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

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com