Olá, estou tentando criar um software que se conecte com o access.
Já criei o banco e já criei o ODBC driver.
Mas da erro toda vez de conexão e não sei que comando usar para receber oos dados.
Criei um arquivo de classe para a conexão:/*
* BancodeDados.java
*
* Created on 05 de Novembro de 2007, 19:03
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package Bancodados1;
import java.sql.*;
/**
*
* @author Thiago_Fonseca
*/
public class BancodeDados {
static Connection conexao;
static Statement comando;
static ResultSet rs;
/** Creates a new instance of DB */
public BancodeDados() {
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conexao = DriverManager.getConnection("jdbc:odbc:BancoTeste");
comando = conexao.createStatement();
//rs = comando.executeQuery("select * from LOGIN");
}catch (SQLException e){
System.out.println("Erro de conexão: "+e.getMessage());
}catch(ClassNotFoundException e){
System.out.println("Driver não encontrado");
}
}
}
E um JFrame para fazer as operações propriamente ditas:
/*
* Busca.java
*
* Created on 5 de Novembro de 2007, 19:37
*/
package Bancodados1;
import java.sql.*;
/**
*
* @author Thiago_Fonseca
*/
public class Busca extends javax.swing.JFrame {
static BancodeDados db = new BancodeDados();
/** Creates new form Busca */
public Busca() {
initComponents();
this.setLocationRelativeTo(null);
try{
db.rs=db.comando.executeQuery("SELECT * FROM Usuarios");
} catch (SQLException e){
System.out.println("Erro na busca do rs: "+e);
}
try{
txtNome.setText(db.rs.getString("nome"));
txtSenha.setText(db.rs.getString("senha"));
} catch (SQLException e){
System.out.println("Erro na busca(): "+e);
}
}
/** 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.
*/
}// <editor-fold>{...}
private void btnInicioActionPerformed(java.awt.event.ActionEvent evt) {
try{
db.rs.first();
txtNome.setText(db.rs.getString("nome"));
txtSenha.setText(db.rs.getString("senha"));
}catch (SQLException e){
System.out.println("Erro: "+e);
}
}
// Declaração de variáveis - não modifique
private javax.swing.JButton btnAnterior;
private javax.swing.JButton btnInicio;
private javax.swing.JButton btnProximo;
private javax.swing.JButton btnUltimo;
private javax.swing.JLabel lblNome;
private javax.swing.JLabel lblSenha;
private javax.swing.JTextField txtNome;
private javax.swing.JTextField txtSenha;
// Fim da declaração de variáveis
}
Por favor, oque que está errado?
Grato