Erro: relation does not exist postgre

1 resposta
javinh
Olá! Estou tentando fazer uma uma conexao simples do eclipse com o postgre, mas nao estou conseguindo, da um erro ERROR: relation "empregado" does not exist, já coloquei o .jar no projeto e já fiz a mesma consulta no postgre e retorna o que eu quero certinho, mas no java da erro, tô esquecendo alguma coisa?
package br.fbd;

import java.sql.*;


public class ConsultaSQL {
	
	 Connection con;
	 Statement stmt;
	 ResultSet rs;
	
	 /** 
	  * Metodo Construtor que se conectar ao banco
	  */
	 public ConsultaSQL() 
	{
		try
		{
		    Class.forName("org.postgresql.Driver");
	        con=DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres","postgres", "");
			stmt = con.createStatement();
		}
       catch(ClassNotFoundException e1) 
       {
          System.out.println(e1.getMessage());
       }
       catch(SQLException e1) 
       {
          System.out.println(e1.getMessage());
       }
	}
	
	
 	public void getConsulta(){
 		String clausula=" select enome, salario " +
	     " from empregado e, departamento d " +
	     " where d.codigo = e.cdep and dnome = 'Marketing' ";

	    try{
	    	rs = stmt.executeQuery(clausula);
	    	String enome;
	    	Double salario;
	    	while(rs.next()){
	    		enome = rs.getString("enome");
	    		System.out.println(enome);
	    		salario = rs.getDouble("salario");
	    		System.out.println(salario);
	    	}	
	    }
	    catch(SQLException e1){ 
	       System.out.println(e1.getMessage());
	    }
	    catch(Exception e1){ 
	       System.out.println(e1.getMessage());
	    }
 	}
   
 }

1 Resposta

javinh
E a classe principal:
package br.fbd;

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class MainFrame extends JFrame {
    private JLabel jLBanco = new JLabel();
    private JButton jButton1 = new JButton();
	private ConsultaSQL consulta = new ConsultaSQL();
    
    public MainFrame() {
        try {
            jbInit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        this.getContentPane().setLayout( null );
        this.setSize(new Dimension(383, 406));
        this.setTitle( "Fundamentos de Banco de Dados" );
        jLBanco.setText("Banco: Postgre ");
        jLBanco.setBounds(new Rectangle(20, 55, 215, 30));
        jButton1.setText("01. Recupere o nome e o salário de todos os empregados que trabalham em Marketing.");
        jButton1.setBounds(new Rectangle(20, 95, 320, 25));
       
        jButton1.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent e) {
        		jButton1_actionPerformed(e);
        	}
        });
        
        this.getContentPane().add(jButton1, null);
        this.getContentPane().add(jLBanco, null);
       
    }

    private void jButton1_actionPerformed(ActionEvent e) {
    	consulta.getConsulta();
	}
}
Criado 21 de setembro de 2008
Ultima resposta 21 de set. de 2008
Respostas 1
Participantes 1