por gentilza será que alguem poderia me dizer onde esta o erro com o codigo a suguir, pois ele estadando erro de sqlException, dizendo que:
o mecanismo dede banco de dados microsoft não encontrou a tabela de entrada ou consulta ‘bd12’, certifique-se que ela exista ou esteja digitada corretamente.SQL passado foi.:select * from bd12.
estou usando o xp 32 bits, netbeans 7.0 e access 2007.
desde ja agradeço.
segue abaixo os codigos das telas de conexão:
1 tela onde é passado o select * from, para selecionar os dados a serem complementados
/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
/*
-
tabela_teste.java
-
Created on 02/11/2011, 22:33:55 <em>/ package utilitarios; import conecta.conexao; import java.sql.SQLException; import javax.swing.JOptionPane; /</em>*
-
@author Edson
*/
public class tabela_teste extends javax.swing.JFrame {conexao conecta_tabela;
/** Creates new form tabela_teste */ public tabela_teste() { initComponents(); conecta_tabela = new conexao(); conecta_tabela.conecta(); conecta_tabela.executeSQL(“Select * from bd12”); try { conecta_tabela.resultset.first(); tf_codigo.setText(conecta_tabela.resultset.getString(“codigo”)); tf_nome.setText(conecta_tabela.resultset.getString(“nome”)); tf_descrição.setText(conecta_tabela.resultset.getString(“descrição”)); } catch(SQLException erro) { JOptionPane.showMessageDialog(null,"Dados não localizados "+erro); } }
/** 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”) // private void initComponents() {
jLabel1 = new javax.swing.JLabel(); jl_codigo = new javax.swing.JLabel(); tf_codigo = new javax.swing.JTextField(); jl_nome = new javax.swing.JLabel(); tf_nome = new javax.swing.JTextField(); jl_descrição = new javax.swing.JLabel(); tf_descrição = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle(“Registros”);jLabel1.setBackground(new java.awt.Color(255, 51, 0)); jLabel1.setFont(new java.awt.Font(“Calibri”, 3, 24)); jLabel1.setText(“Dados do registro a serem analisados.:”);
jl_codigo.setText(“Codigo.:”);jl_nome.setText(“Nome.:”);tf_nome.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { tf_nomeActionPerformed(evt); } });
jl_descrição.setText(“Descrição.:”);javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(19, 19, 19) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jl_descrição) .addComponent(jl_codigo) .addComponent(jl_nome)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(tf_descrição) .addComponent(tf_nome) .addComponent(tf_codigo, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)))) .addContainerGap(29, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jl_codigo) .addComponent(tf_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(29, 29, 29) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(tf_nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jl_nome)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jl_descrição) .addComponent(tf_descrição, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(134, Short.MAX_VALUE)) );
pack();
}//
private void tf_nomeActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: }
/**
-
@param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() {
public void run() { new tabela_teste().setVisible(true); }
}); } // Variables declaration - do not modify private javax.swing.JLabel jLabel1; private javax.swing.JLabel jl_codigo; private javax.swing.JLabel jl_descrição; private javax.swing.JLabel jl_nome; private javax.swing.JTextField tf_codigo; private javax.swing.JTextField tf_descrição; private javax.swing.JTextField tf_nome; // End of variables declaration }
-
2 tabela com o metodo conecta:
package conecta;
import java.sql.<em>;
import javax.swing.</em>;
public class conexao
{
final private String driver = “sun.jdbc.odbc.JdbcOdbcDriver”;
final private String url = “jdbc:odbc:bd12”;
final private String usuario= “”;
final private String senha = “”;
private Connection conexao;
public Statement statement;
public ResultSet resultset;
public boolean conecta()
{
boolean result = true;
try
{
Class.forName(driver);
conexao = DriverManager.getConnection(url,usuario,senha);
JOptionPane.showMessageDialog(null,“conexão realizada com sucesso”);
}
catch(ClassNotFoundException Driver)
{
JOptionPane.showMessageDialog(null,“Driver não localizado”+Driver);
result = false;
}
catch(SQLException Fonte)
{
JOptionPane.showMessageDialog(null,“Erro de conexão com a fonte de dados”+Fonte);
result = false;
}
return result;
}
public void desconecta()
{
boolean result = true;
try
{
conexao.close();
JOptionPane.showMessageDialog(null,“banco de Dados fechado”);
}
catch(SQLException erroSQL)
{
JOptionPane.showMessageDialog(null,“Não foi possível fechar o banco”+erroSQL);
result = false;
}
}
public void executeSQL(String sql)
{
try
{
statement = conexao.createStatement(resultset.TYPE_SCROLL_SENSITIVE,resultset.CONCUR_READ_ONLY);
resultset = statement.executeQuery(sql);
}
catch(SQLException sqlex)
{
JOptionPane.showMessageDialog(null,"erro.: "+sqlex+"SQL passado.: "+sql);
}
}
}