Conexão com o postgresql?

2 respostas
ITAMB

Por favor me ajudem estou finalizando meu TCC, estou usando eclipse 3.2 e o BD postgresql.

Meu projeto já está pronto e rodando, só que quando peço para incluir não consigo mais nada.

Minha classe de conexão é:

package DAOGenerics;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public abstract class GenericDAO<T, ID extends Serializable> implements IGenericDAO<T, ID> {
  private String driverClass;
  private String dbURL;
  private String dbName;
  private String user;
  private String passwd;
  
  protected Connection con = null;
  protected PreparedStatement ps;
  protected ResultSet rs; 
  
  /** Creates a new instance of GenericDAO */
 
public GenericDAO() {
    this.driverClass = "org.postgresql.Driver";
    this.dbURL = "jdbc:PostgreSQL:";
    this.dbName = "AutoCenter";
    this.user = "postgres";
    this.passwd = "postgres";
    this.passwd = "post";
  }
  
  public GenericDAO(String dataBase, String dbName, 
                    String user, String passwd ) {
    
    if( dataBase.equalsIgnoreCase("postgresql") ) {
      driverClass = "org.postgresql.Driver";
      dbURL = "jdbc:postgresql:";    
    }
    else if ( dataBase.equalsIgnoreCase("mysql") ) {
      driverClass = "org.gjt.mm.mysql.Driver";
      dbURL = "jdbc:mysql:";
    }
    else if ( dataBase.equalsIgnoreCase("jdbcodbc") ) {
      driverClass = "sun.jdbc.odbc.JdbcOdbcDriver";
      dbURL = "jdbc:odbc:";
    }
      
    this.dbName = dbName;
    this.user = user;
    this.passwd = passwd;
  }
  
  private void getConnection() throws DAOException {
    if( con != null )
      return;
     System.out.println("v1=abrindo banco: " + dbName );
    try {
      Class.forName(driverClass);   // "org.postgresql.Driver"
       String url = dbURL + dbName;  // "jdbc:postgresql:" + "postgres"
     
      con = DriverManager.getConnection(url, user, passwd);

    } catch (ClassNotFoundException ex) {
      throw new DAOException("SQL exception in getConnection", ex);
    } catch (SQLException ex) {
      throw new DAOException("SQL exception in getConnection" , ex);
    }
  }
  
  
  public void closeConnection() throws DAOException {
    try {
      if (con!=null){
        con.close();
      }
      con = null;
    } catch (SQLException ex) {
      throw new DAOException("SQL exception in closeConnection" , ex);
    }
  }
  public void getPreparedStatement(String query) throws DAOException {
    try {
      getConnection();
      ps = con.prepareStatement(query,rs.TYPE_SCROLL_INSENSITIVE, rs.CONCUR_UPDATABLE);
    } catch (SQLException ex) {
      throw new DAOException("SQL exception in getPreparedStatement" , ex);
    }
  }

  public void closePreparedStatement() throws DAOException {
    try {
      ps.close();
      closeConnection();
    } catch (SQLException ex) {
      throw new DAOException("SQL exception in closePreparedStatement" , ex);
    }
  }
}

O erro é o seguinte:


Já verifiquei o nome do banco com a url e a senha só que não descobri o erro, por favor me ajudem.

2 Respostas

maquiavelbona
Caused by: java.lang.ClassNotFoundException: org.postgresql.Driver

Isso tava no meio da sua stacktrace. Isso é problema comum aqui no fórum. Procure que lá tem todas as soluçõe possíveis e imagináveis.

Até!

ITAMB

Agradeço ajuda, consegui conexão em outro computador com postgre e o eclipse. Desde já agradeço. :lol:

Criado 8 de julho de 2008
Ultima resposta 10 de jul. de 2008
Respostas 2
Participantes 2