Erro ODBC

2 respostas
carioca

Pessoal, estou com um probleminha em meu sistema.
Tenho uma agenda telefonica feita em java, onde posso pesquisar por nome e por referencia(palavra chave), quando pesquiso por nome, funciona tudo certo mas por referencia nao da certo. Da o seguinte erro.

[Microsoft][Driver ODBC para Microsoft Access]Erro interno de Automação OLE

Alguem sabe pq esta dando esse erro.

2 Respostas

LN2EE

cara,
esta meio dificil de te ajudar, manda o codigo pra gente dar uma olhada…

Falow

carioca

Aqui esta o codigo

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;

public class consulta_agenda extends JFrame{
	
	JLabel l0, barra_hor;
	JTextField t1, t2, t3, t4, t5, t6, t7, t8;
	JButton alterar, fechar;
	Container c;
	Connection connection;
	int op = 0;
	int matr;
	
	public consulta_agenda(){
		
		super(".:G A M E   A C T I O N:. - Consultando um telefone na agenda: ");
		setLocation(0,0);
				
		c = new Container();
		c = getContentPane();
		c.setLayout(new FlowLayout());
		
		String url = "jdbc:odbc:vet";  
      	String username = "anonymous";
      	String password = "guest";

      	// Load the driver to allow connection to the database
      	try {
         	Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );

         	connection = DriverManager.getConnection(url, username, password );
      	} 
      	catch ( ClassNotFoundException cnfex ) {
         	System.err.println( "Failed to load JDBC/ODBC driver." );
			cnfex.printStackTrace();
        	System.exit( 1 );  // terminate program
      	}
      	catch ( SQLException sqlex ) {
        	System.err.println( "Não foi possível conectar" );
        	sqlex.printStackTrace();
      	}
		
//------ADICIONANDO COMPONENTES		
				
		barra_hor =new JLabel("                                                                                                                     ");
		c.add(barra_hor);				
					
				
		barra_hor =new JLabel("                                    L O C A D O R A   G A M E   A C T I O N   L T D A                                ");
		c.add(barra_hor);		
		
		barra_hor =new JLabel("                                            CADASTRANDO UM TELEFONE NA AGENDA                                        ");
		c.add(barra_hor);		
			
		
		barra_hor =new JLabel("_____________________________________________________________________________________________________________");
		c.add(barra_hor);

		
		l0 = new JLabel("Nome: ");
		c.add(l0);
		t1 = new JTextField(29);
		t1.setEditable(false);
		c.add(t1);
								
		l0 = new JLabel("Referência: ");
		c.add(l0);
		t2 = new JTextField(29);
		t2.setEditable(false);
		c.add(t2);
						
		l0 = new JLabel("Endereço: ");
		c.add(l0);
		t3 = new JTextField(19);
		t3.setEditable(false);
		c.add(t3);
						
		l0 = new JLabel("Bairro: ");
		c.add(l0);
		t4 = new JTextField(17);
		t4.setEditable(false);
		c.add(t4);
						
		l0 = new JLabel("Cidade: ");
		c.add(l0);
		t5 = new JTextField(17);
		t5.setEditable(false);
		c.add(t5);
					
		l0 = new JLabel("Telefone Residencial: ");
		c.add(l0);
		t6 = new JTextField(12);
		t6.setEditable(false);
		c.add(t6);
		
		l0 = new JLabel("Telefone Comercial: ");
		c.add(l0);
		t7 = new JTextField(12);
		t7.setEditable(false);
		c.add(t7);
						
		l0 = new JLabel("Telefone Celular: ");
		c.add(l0);
		t8 = new JTextField(12);
		t8.setEditable(false);
		c.add(t8);
		
		alterar = new JButton("Alterar");
		c.add(alterar);
		
		fechar = new JButton("Fechar");
		c.add(fechar);
		
		setSize(800,575);
		show();
		
		fechar.addActionListener(
			new ActionListener(){
				public void actionPerformed(ActionEvent e) 
				{
					dispose();
				}
			}
		);
		
		alterar.addActionListener(
			new ActionListener(){
				public void actionPerformed(ActionEvent e) 
				{
					
					if(op == 0){
							
						t1.setEditable(true);
						t2.setEditable(true);
						t3.setEditable(true);
						t4.setEditable(true);
						t5.setEditable(true);
						t6.setEditable(true);
						t7.setEditable(true);
						t8.setEditable(true);
						alterar.setText("Salvar");
						op = 1;
						fechar.setEnabled(false);
						repaint();
					}
					else{
						
						try{
							Statement statement = connection.createStatement();
							String query = "UPDATE agenda SET " +
				       		"nome='" + t1.getText() + 
					       	"', ref='" + t2.getText() + 
				    	   	"', end='" + t3.getText() + 
				    	   	"', bairro='" + t4.getText() + 
				    	   	"', cidade='" + t5.getText() + 
				    	   	"', foneres='" + t6.getText() + 
				    	   	"', fonecom='" + t7.getText() + 
				    	   	"', fonecel='" + t8.getText() + 
				    	   	"' WHERE matr=" + matr;
							int result = statement.executeUpdate( query );
						}
						catch ( SQLException sqlex ) {
				         	sqlex.printStackTrace();
				         	JOptionPane.showMessageDialog(null, sqlex.toString() );
				      	}
							
						t1.setEditable(false);
						t2.setEditable(false);
						t3.setEditable(false);
						t4.setEditable(false);
						t5.setEditable(false);
						t6.setEditable(false);
						t7.setEditable(false);
						t8.setEditable(false);
						alterar.setText("Alterar");
						op = 0;
						fechar.setEnabled(true);
						repaint();
					}
					
				}
			}
		);
		
		try{
			
			RandomAccessFile temp = new RandomAccessFile("dbtemp.dat","rw");
			matr = temp.readInt();
			temp.close();
	
			Statement statement = connection.createStatement();
			String query = "SELECT * FROM agenda WHERE matr= "+matr;
			ResultSet rs = statement.executeQuery( query );
			
			rs.next();
			
			t1.setText(rs.getString(2));
			t2.setText(rs.getString(3));
			t3.setText(rs.getString(4));
			t4.setText(rs.getString(5));
			t5.setText(rs.getString(6));
			t6.setText(rs.getString(7));
			t7.setText(rs.getString(8));
			t8.setText(rs.getString(9));
		}
		catch ( SQLException sqlex ) {
			sqlex.printStackTrace();
			JOptionPane.showMessageDialog(null, sqlex.toString());
		}
		catch(IOException tempex){
			JOptionPane.showMessageDialog(null, tempex.toString());
		}
	}
}//main
Criado 8 de março de 2003
Ultima resposta 10 de mar. de 2003
Respostas 2
Participantes 2