Jump to content

Extrair informação de BD para Jtable


Ruben_Barbosa
 Share

Recommended Posts

  try {
            BD bd = new BD();
            JConsulta = (DefaultTableModel) this.jTableArtigos.getModel();
            // chamamos a função "executeQuery", que devolve um ResultSet (Tabela de Resultados)
            ResultSet rs = bd.execquery("SELECT * FROM Artigos ORDER BY Designação ASC");
            //            ResultSetMetaData rsmd = rs.getMetaData();
            String Codigo = new String(rs.getString("CodArtigo"));
            String Desig = new String(rs.getString("Designação"));
            while (rs.next()) {
                JConsulta.addRow(new Object[]{Codigo, Desig});
                System.out.println("Codigo Artigo:" + rs.getString(0) + "Designação: " + rs.getString(1));
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(JFrameConArtigos.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(JFrameConArtigos.class.getName()).log(Level.SEVERE, null, ex);
        }

Porque não me estrai os dados :|.

não estou vendo o Erro :|.

Da-me o seguinte erro

Controlador Microsoft ACCESS ODBC - Poucos parametros.1 Esperado
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at jlamieconomato.BD.execquery(BD.java:42)
Linha 42 --> rs.close();
at jlamieconomato.JFrameConArtigos.formComponentShown(JFrameConArtigos.java:100)
linha 100 --> ResultSet rs = bd.execquery("SELECT * FROM Artigos ORDER BY Designação ASC");

Mas eu passo os parametros todos :|.

Porque a minha tabela so tem  2 Campos :|

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.