Boa noite pessoal,
Tenho em minha aplicação uma tabela que, conforme eu aperto os botoes ela me montra um result diferente:
package Estoque;
import java.awt.BorderLayout;
import java.sql.SQLException;
import javax.swing.*;
@SuppressWarnings("serial")
public class Tabela extends JDialog
{
static ImageIcon Icon = new ImageIcon("table_go.png");
static final String DRIVER = "com.mysql.jdbc.Driver";
static final String URL = "jdbc:mysql://localhost/Estoque";
static final String USER = "root";
static final String PASS = "";
private ResultSetTableModel tableModel;
static JTable resultTable;
public static JScrollPane Scroller;
public Tabela(String SQL)
{
try
{
setUndecorated(true);
getRootPane().setWindowDecorationStyle(1);
this.setAlwaysOnTop(true);
tableModel = new ResultSetTableModel(DRIVER, URL, USER, PASS, SQL);
resultTable = new JTable(tableModel); resultTable.setFillsViewportHeight(true);
Scroller = new JScrollPane(resultTable);
add(Scroller, BorderLayout.CENTER);
setSize(500,300);
setVisible(false);
setIconImage(Icon.getImage());
setResizable(false);
}
catch (ClassNotFoundException classNotFound)
{
JOptionPane.showMessageDialog(null, "Driver MySQL não encontrado", "Erro", JOptionPane.ERROR_MESSAGE );
System.exit(1);
}
catch (SQLException sqlException)
{
JOptionPane.showMessageDialog(null,sqlException.getMessage(), "Erro no Banco de Dados", JOptionPane.ERROR_MESSAGE );
tableModel.disconnectFromDatabase();
System.exit(1);
}
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
public void atualizaBD(String query)
{
try
{
tableModel.setQuery(query);
}
catch (SQLException sqlException)
{
JOptionPane.showMessageDialog(null,sqlException.getMessage(), "Erro no Banco de Dados", JOptionPane.ERROR_MESSAGE );
try
{
tableModel.setQuery("SELECT * FROM Produto");
}
catch (SQLException sqlException2)
{
JOptionPane.showMessageDialog(null,sqlException.getMessage(), "Erro no Banco de Dados", JOptionPane.ERROR_MESSAGE );
tableModel.disconnectFromDatabase();
System.exit(1);
}
}
}
public static void main (String[] args)
{
new Tabela("SELECT * FROM Produto");
}
}
só que quando eu chamo a tabela
if (e.getSource()== registraEntrada)
{
Componente.Entrada.setVisible(true);
cadEntrada.setBotoes(true,true,false,false,false);
cadEntrada.setTexts(true, false, false);
}
ela me mostra um resultado diferente!
ele me mostra dados de outra tabela, que eu chamaria por outro botao…
como eu faço para que isso nao aconteça?..