Olá galera, eu preciso fazer um programa para fluxo de caixa em que na qual os dados seram salvos no access, porem naum to conseguindo fazer a conexão com o access, está dando alguns erros...
janela principal...import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class fluxo_de_caixa extends javax.swing.JFrame {
private Connection conexao;
private Statement comando;
private static ResultSet resultado;
private static String driver,url;
/** Creates new form fluxo_de_caixa */
public fluxo_de_caixa() {
initComponents();
driver="sun.jdbc.odbc.JdbcOdbcDriver";
url="jdbc:odbc:BD";
setTitle("Navegando no Banco de Dados");
setVisible(true);
pack();
}
/** 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() {
Saída = new javax.swing.JButton();
Entrada = new javax.swing.JButton();
RelatórioMensal = new javax.swing.JButton();
RelatórioAnual = new javax.swing.JButton();
Sair = new javax.swing.JButton();
jMenuBar1 = new javax.swing.JMenuBar();
Arquivo = new javax.swing.JMenu();
SaídadeCaixaMenu = new javax.swing.JMenuItem();
EntradadeCaixaMenu = new javax.swing.JMenuItem();
RelatórioMensalMenu = new javax.swing.JMenuItem();
RelatórioAnualMenu = new javax.swing.JMenuItem();
SairMenu = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("FluxCa");
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
Saída.setText("Saída");
Saída.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SaídaActionPerformed(evt);
}
});
Entrada.setText("Entrada");
Entrada.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EntradaActionPerformed(evt);
}
});
RelatórioMensal.setText("Relatório Mensal");
RelatórioMensal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RelatórioMensalActionPerformed(evt);
}
});
RelatórioAnual.setText("Relatório Anual");
RelatórioAnual.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RelatórioAnualActionPerformed(evt);
}
});
Sair.setText("Sair");
Sair.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SairActionPerformed(evt);
}
});
Arquivo.setText("Arquivo");
SaídadeCaixaMenu.setText("Saída de Caixa");
SaídadeCaixaMenu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SaídadeCaixaMenuActionPerformed(evt);
}
});
Arquivo.add(SaídadeCaixaMenu);
EntradadeCaixaMenu.setText("Entrada de Caixa");
EntradadeCaixaMenu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EntradadeCaixaMenuActionPerformed(evt);
}
});
Arquivo.add(EntradadeCaixaMenu);
RelatórioMensalMenu.setText("Relatório Mensal");
RelatórioMensalMenu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RelatórioMensalMenuActionPerformed(evt);
}
});
Arquivo.add(RelatórioMensalMenu);
RelatórioAnualMenu.setText("Relatório anual");
RelatórioAnualMenu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RelatórioAnualMenuActionPerformed(evt);
}
});
Arquivo.add(RelatórioAnualMenu);
SairMenu.setText("Sair");
SairMenu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SairMenuActionPerformed(evt);
}
});
Arquivo.add(SairMenu);
jMenuBar1.add(Arquivo);
setJMenuBar(jMenuBar1);
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(33, 33, 33)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(RelatórioAnual, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
.addComponent(RelatórioMensal, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(Saída, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 75, Short.MAX_VALUE)
.addComponent(Entrada)))
.addGap(28, 28, 28))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(113, Short.MAX_VALUE)
.addComponent(Sair)
.addGap(111, 111, 111))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Saída)
.addComponent(Entrada))
.addGap(33, 33, 33)
.addComponent(RelatórioMensal)
.addGap(35, 35, 35)
.addComponent(RelatórioAnual)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
.addComponent(Sair)
.addGap(25, 25, 25))
);
getAccessibleContext().setAccessibleDescription("Fluxo de Caixa");
pack();
}// </editor-fold>
private void SairActionPerformed(java.awt.event.ActionEvent evt) {
desconecta();
this.setDefaultCloseOperation(fluxo_de_caixa.DISPOSE_ON_CLOSE);
this.setVisible(false);
this.dispose(); // TODO add your handling code here:
}
private void SairMenuActionPerformed(java.awt.event.ActionEvent evt) {
desconecta();
this.setDefaultCloseOperation(fluxo_de_caixa.DISPOSE_ON_CLOSE);
this.setVisible(false);
this.dispose(); // TODO add your handling code here:
}
private void SaídaActionPerformed(java.awt.event.ActionEvent evt) {
new Saída().setVisible(true);// TODO add your handling code here:
}
private void EntradaActionPerformed(java.awt.event.ActionEvent evt) {
new Entrada().setVisible(true);// TODO add your handling code here:
}
private void RelatórioMensalActionPerformed(java.awt.event.ActionEvent evt) {
new RelatórioMensal().setVisible(true);// TODO add your handling code here:
}
private void RelatórioAnualActionPerformed(java.awt.event.ActionEvent evt) {
new RelatórioAnual().setVisible(true);// TODO add your handling code here:
}
private void SaídadeCaixaMenuActionPerformed(java.awt.event.ActionEvent evt) {
new Saída().setVisible(true);// TODO add your handling code here:
}
private void EntradadeCaixaMenuActionPerformed(java.awt.event.ActionEvent evt) {
new Entrada().setVisible(true);// TODO add your handling code here:
}
private void RelatórioMensalMenuActionPerformed(java.awt.event.ActionEvent evt) {
new RelatórioMensal().setVisible(true);// TODO add your handling code here:
}
private void RelatórioAnualMenuActionPerformed(java.awt.event.ActionEvent evt) {
new RelatórioAnual().setVisible(true);// 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 fluxo_de_caixa().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JMenu Arquivo;
private javax.swing.JButton Entrada;
private javax.swing.JMenuItem EntradadeCaixaMenu;
private javax.swing.JButton RelatórioAnual;
private javax.swing.JMenuItem RelatórioAnualMenu;
private javax.swing.JButton RelatórioMensal;
private javax.swing.JMenuItem RelatórioMensalMenu;
private javax.swing.JButton Sair;
private javax.swing.JMenuItem SairMenu;
private javax.swing.JButton Saída;
private javax.swing.JMenuItem SaídadeCaixaMenu;
private javax.swing.JMenuBar jMenuBar1;
// End of variables declaration
public void conecta(){
try{
Class.forName(driver);
conexao=DriverManager.getConnection(url,"","");
comando=conexao.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
resultado=comando.executeQuery(access);
System.out.println("Conexão executada com sucesso");
// atualizaCampos();
ResultSet rs = comando.executeQuery("SELECT * FROM IC");
while (rs.next())
{
System.out.println("Nome: " + rs.getString("nome"));
}
}
catch(SQLException AccessExc){
System.out.println("Erro de SQL8!");
}
catch(ClassNotFoundException exc){
System.out.println("Classe não encontrada!");
}
}
public void desconecta(){
try{
conexao.close();
}
catch(SQLException SqlExc){
System.out.println("Erro de SQL3!");
}
}
}
import java.sql.*;
public class TestaConexao{
private String driver,url;
private Connection conexao;
public TestaConexao(){
driver="sun.jdbc.odbc.JdbcOdbcDriver";
url="jdbc:odbc:BD"; // nome dado ao banco
conecta(driver,url);
}
public void conecta(String driver, String url){
try{
// carrega o driver da ponte jdbc-odbc
Class.forName(driver);
// abre conexao com o banco de dados
conexao=DriverManager.getConnection(url,"","");
System.out.println("Conexão executada com sucesso");
conexao.close();
}
catch(SQLException SqlExc){
System.out.println("Erro de SQL!");
}
catch(ClassNotFoundException exc){
System.out.println("Classe não encontrada!");
}
}
public static void main(String args[]){
TestaConexao ins=new TestaConexao();
}
}
public class TestaDML{
private static String driver,url;
private Connection conexao;
private Statement comando;
private static ResultSet resultado;
public TestaDML(){
driver="sun.jdbc.odbc.JdbcOdbcDriver";
url="jdbc:odbc:BD"; //nome do banco
}
public void conecta(){
try{
// carrega o driver da ponte jdbc-odbc
Class.forName(driver);
// abre conexao com o banco de dados
conexao=DriverManager.getConnection(url,"","");
System.out.println("Conexão executada com sucesso");
}
catch(SQLException SqlExc){
System.out.println("Erro de SQL!");
}
catch(ClassNotFoundException exc){
System.out.println("Classe não encontrada!");
}
}
//public void listaDados (){
// String sql="select * from CD";
// try{
// comando=conexao.createStatement();
// resultado=comando.executeQuery(sql);
// while(resultado.next()){
// String nome =resultado.getString(?nome");
// String datacompra =resultado.getString(?datacompra");
// String localcompra =resultado.getString(?localcompra");
// String valor =resultado.getString(?valor");
// System.out.println(?Nome: "+nome+...);
// }
// }
// catch(SQLException SqlExc){
// System.out.println("Erro de SQL!");
// } }
public void desconecta(){
try{
conexao.close();
}
catch(SQLException SqlExc){
System.out.println("Erro de SQL!");
}
}
public static void main(String args[]){
TestaDML tdml=new TestaDML();
tdml.conecta();
// tdml.listaDados();
tdml.desconecta();
}
}
Eu utilizo o NetBeans 6.7.1, o banco de dados se xama IC e o drive se xama BD...
Por favor, preciso disso urgentemente, pois tenho que apresentar esse programa dia 30/11