Ola pessoal,
Realmente a partir da versao 6 o NetBeans nao tem essa opcao de Form Connection.
Eu estava a um tempo atras com o mesmo problema que os dois, com o mesmo livro na mao, e na mesma pagina, e consegui resolver o problema da seguinte forma :
1 - criei um metodo myinit() e fiz sua chamada antes do initComponents() do NetBeans
2 - fiz o metodo getResults() na mao mesmo.
3 - fiz algumas moficacoes nas classes TableModel e na minha interface.
Vou postar o codigo aqui para que voces tomem como base na hora de implementar.
package trabbancodedados;
import java.sql.ResultSet;
import br.com.integrator.conexaoBanco.ConnectionFactory;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.sql.Statement;
public class EJTableGUI extends javax.swing.JFrame {
ConnectionFactory conexao;
ResultSet rs = null;
Statement stmt = null;
/** Creates new form EJTableGUI */
public EJTableGUI() throws SQLException {
try {
conexao = new ConnectionFactory();
Connection conn = conexao.getConexao();
stmt = conn.createStatement();
} catch (InstantiationException ex) {
ex.printStackTrace();
}
myinit();
initComponents();
}
public void myinit() {
rs = getResults();
try {
jTable1.setModel(new TabelaModel(rs));
} catch (SQLException ex) {
Logger.getLogger(EJTableGUI.class.getName()).log(Level.SEVERE, null, ex);
}
conexao.fechaConexao();
}
private ResultSet getResults() {
try {
rs = stmt.executeQuery("Select * from livros");
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane1.setViewportView(jTable1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(13, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(162, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(31, 31, 31))
);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-400)/2, (screenSize.height-325)/2, 400, 325);
}// </editor-fold>
private void formWindowClosing(java.awt.event.WindowEvent evt) {
conexao.fechar(stmt);
conexao.fechaConexao();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
new EJTableGUI().setVisible(true);
} catch (SQLException ex) {
ex.printStackTrace();
}
}
});
}
// Variables declaration - do not modify
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration
}
e aqui esta a classe TableModel
package trabbancodedados;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import javax.swing.table.AbstractTableModel;
public class TabelaModel extends AbstractTableModel {
private int colunas;
private int linhas;
private ResultSet resultset;
private ResultSetMetaData rs_metadata;
public TabelaModel(ResultSet rs) throws SQLException {
resultset = rs;
rs_metadata = rs.getMetaData();
//determina o numero de linhas em um resultset
rs.last(); //move para a ultima linha linha
rs.getRow(); // pega o numero da linha
//notifica JTable das alteracoes
fireTableStructureChanged();
}
public int getRowCount() {
return linhas;
}
public int getColumnCount() {
try {
return rs_metadata.getColumnCount();
} catch (SQLException sqlException) {
sqlException.printStackTrace();
}
//se houver problemas e nao satisfazer a condicao try acima
// eh retornado 0 para o numero de colunas
return 0;
}
public Object getValueAt(int rowIndex, int columnIndex) {
try {
resultset.absolute(rowIndex + 1);
return resultset.getObject(columnIndex + 1);
} catch (SQLException ex) {
ex.printStackTrace();
}
return "";
}
public String getColumnName(int column) {
//determina o nome da coluna
try {
return rs_metadata.getCatalogName(column + 1);
} catch (SQLException e) {
e.printStackTrace();
}
return "";
}
}
obs : como estava usando Oracle e nao Mysql tive que fazer outras modifcacoes ainda, mas o exemplo acima eh para MySql mesmo.
Espero que ajude,
flw.