Vou por os trechos de código relacionados aqui:
Primeiro o select:
public class Operacoes {
Connection con;
public Object[][] select(String table, String table2, String igualdade, String fields, String where, String order, Connection con) {
int registros = 0;
String colname[] = fields.split(",");
//Consultas SQL
String q = "SELECT " + fields + " FROM " + table;
String q2 = "SELECT count(*) as total FROM " + table;
if (igualdade != null) {
if (table2 != null) {
if (where != null) {
q += " INNER JOIN " + table2 + " ON " + igualdade + " WHERE " + where;
}
}
} else if (where != null) {
q += " WHERE " + where;
q2 += " WHERE " + where;
}
if (order != null) {
q += " ORDER BY " + order;
}
try {
PreparedStatement pstm = con.prepareStatement(q2);
ResultSet res = pstm.executeQuery();
res.next();
registros = res.getInt("total");
res.close();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, e.getLocalizedMessage());
}
//se crea una matriz con tantas filas y columnas que necesite
Object[][] data = new String[registros][fields.split(",").length];
//realizamos la consulta sql y llenamos los datos en la matriz "Object"
try {
PreparedStatement pstm = con.prepareStatement(q);
ResultSet res = pstm.executeQuery();
int i = 0;
while (res.next()) {
for (int j = 0; j <= fields.split(",").length - 1; j++) {
data[i][j] = res.getString(colname[j].trim());
}
i++;
}
res.close();
} catch (SQLException e) {
System.out.println(e);
}
return data;
}
Ai eu criei um método assim:
public Object[][] getObjetivoDecisao(int mode, Connection con) {
Object[][] res = this.select(" OBJETIVO ", " DECISAO ", " OBJETIVO.IDDECISAO = DECISAO.ID ", " OBJETIVO.TITULO_OBJETIVO ", " DECISAO.ID = " + mode, " OBJETIVO.TITULO_OBJETIVO ", con);
if (res.length > 0) {
return res;
} else {
return null;
}
}
Chamo o método assim ( esse vai na J frame ) : Esse btnincluir na tabela um objetivo:
if (!txtTituloObj.getText().isEmpty()) {
if (!txtDescricaoOBJ.getText().isEmpty()) {
mod.setPesquisa(txtRegTituloDecisao.getText());
BeansDecisao mode = dec.busca(mod);
modo.setTituloObjetivo(txtTituloObj.getText());
modo.setDescricaoObjetivo(txtDescricaoOBJ.getText());
modo.setIdDecisao(mode.getCodigo());
cont.salvar(modo);
JOptionPane.showMessageDialog(null, "Salvo!");
txtDescricaoOBJ.setText("");
txtTituloObj.setText("");
atualizjTableObjetivos();
} else {
JOptionPane.showMessageDialog(null, "Favor preencher a descrição do Obijetivo!");
}
} else {
JOptionPane.showMessageDialog(null, "Favor preencher o título do objetivo!");
}
Esse no mesmo jframe do btnincluir traz os valores à tabela junto com o primeiro código (vcs já sabem disso),
public void atualizjTableObjetivos() {
String[] columNames = {"Descrição"};
mod.setPesquisa(txtRegTituloDecisao.getText());
BeansDecisao mode = dec.busca(mod);
dtCli = op.getObjetivoDecisao(mode.getCodigo(), con);
datoscli = new DefaultTableModel(dtCli, columNames);
jTableObjetivos.setModel(datoscli);
}
mas qual é o meu problema afinal?
quando eu insiro a minha decisão, consigo inserir os objetivos normal, mas a partir da segunda, objetivos do join ficam em branco na tabela, aparecem vários em branco e eu nem consigo ver em outra tela… queria ajuda empaquei nisso!
