Onde está a implementação do método displayResultSet(ResultSet)??? :?
Re: displayResultSet
3 Respostas
isso q da copiar codigo da net sem prestar atenção
private void displayResultSet(ResultSet rs) throws SQLException {
boolean moreRecords = rs.next();
if (!moreRecords) {
JOptionPane.showMessageDialog(this, "Nao existem registros na tabela");
setTitle("Registros vazios");
return;
}
setTitle("Listagem Geral dos dados - Tabela obra - bancodeDados");
Vector columnHeads = new Vector();
Vector rows = new Vector();
try {
ResultSetMetaData rsmd = rs.getMetaData();
for (int i = 1; i <= rsmd.getColumnCount(); ++i)
columnHeads.addElement(rsmd.getColumnName(i));
do {
rows.addElement(getNextRow(rs, rsmd));
} while (rs.next());
validate();
} catch (SQLException sqlex) {
sqlex.printStackTrace();
}
}
http://www.portaljava.com/home/modules.php?name=Forums&file=viewtopic&t=20074
T
implementei o seguinte código:
import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Livros extends JFrame {
private JPanel fundo;
private JButton listar;
private JTable tabela;
private Connection connection;
public Livros(){
super("Cadastro de Livros");
listar = new JButton("Listar");
fundo = new JPanel(new FlowLayout());
tabela = new JTable( 10, 5 );
JScrollPane scroller = new JScrollPane( tabela );
String url = "jdbc:odbc:Books1";
String username = "anonymous";
String password = "guest";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch ( ClassNotFoundException cnfex ) {
System.err.println(
"Failed to load JDBC/ODBC driver." );
cnfex.printStackTrace();
System.exit( 1 );
}/*catch ( SQLException sqlex ) {
System.err.println( "Unable to connect" );
sqlex.printStackTrace();
}*/
getTable();
setSize( 450, 150 );
show();
}
private void getTable()
{
Statement statement;
ResultSet resultSet;
try {
String query = "SELECT * FROM Authors";
statement = connection.createStatement();
resultSet = statement.executeQuery( query );
displayResultSet( resultSet );
//System.out.println(resultSet);
statement.close();
}catch ( SQLException sqlex ) {
sqlex.printStackTrace();
}catch ( NullPointerException e ) {
e.printStackTrace();
}
}
public void init() {
setForeground(Color.black);
setBackground(new Color(192,192,192,192));
setLocation(200, 130);
setSize(640, 480);
getContentPane().setLayout(new BorderLayout());
fundo.add(listar);
getContentPane().add(fundo, BorderLayout.NORTH);
getContentPane().add(tabela, BorderLayout.SOUTH);
setVisible(true);
}
public static void main(String args[]){
new Livros().init();
}
}
e está aparecendo o erro em anexo
T
private void getTable()
{
Statement statement;
ResultSet resultSet;
try {
String query = "SELECT * FROM Authors";
statement = connection.createStatement();
resultSet = statement.executeQuery( query );
displayResultSet( resultSet );
//System.out.println(resultSet);
statement.close();
}catch ( SQLException sqlex ) {
sqlex.printStackTrace();
}catch ( NullPointerException e ) {
e.printStackTrace();
}
}
Criado 22 de junho de 2005
Ultima resposta 22 de jun. de 2005
Respostas 3
Participantes 3
Alura POO: o que é programação orientada a objetos? Aprenda os conceitos básicos da programação orientada a objetos, como classes, objetos, herança, encapsulamento e polimorfismo, com exemplos.
Casa do Codigo Inteligencia Artificial e ChatGPT: Da revolucao dos... Por Fabricio Carraro — Casa do Codigo