Thread: a big question

a big question

From
Dam Avalos
Date:
Hi!
I have a big problem with the postgress driver, and i hope you can help me, i�m programming with java, and java has a method name Class.forName() that ask for the postgress driver... I send you the archive ConexionBD.java, and i hope you can help me, because when i run the program it says that it can�t get the driver, or found the driver, or something like that, so, well if you can help me i�ll be very gratefull with you, thanks a lot 
 
/*
ARCHIVO: ConexionBD.java
AUTOR:   Daniela Avalos Monroy
         aleidam8@yahoo.com
Programa que hace una conexion a Base de Datos
realizada en postgress por medio de codigo en
Java*/
package libro.src;
import java.sql.*;
import java.net.URL;
public class ConexionBD
{
    //Los datos de configuracion
    static String URL = "jdbc:postgresql://ada.fciencias.unam.mx/libroo";//Nombre de la base de datos.
    static String USER = "davalosm";
    static String PASSWD = "";
    Connection con = null;
    Statement stmt=null;
 
    public ConexionBD()
        {}

    /**Esta funcion establece una conexion  a  la BD.*/
    public void openConexion()
        {
            System.out.println(" Estableciendo conexion...");
            try
     {
  //Class.forName("postgresql.Driver"); //Cualquiera de los 2 funciona.
  Class.forName("org.postgresql.Driver"); //Cualquiera de los 2 funciona.
     }
            catch(Exception e)
     {
  System.out.println("No se puede cargar el driver de psql.");
     }
            System.out.println("Driver de psql cargado con exito...!!!.");

            try
            {
                con = DriverManager.getConnection(URL, USER, PASSWD);
                System.out.println("Conexion establecida...");
     }
            catch( Exception e)
     {
  e.printStackTrace();
     }
        }
   
   
    /*Esta funcion cierra la conexion*/
    public void closeConexion()
        {
            try
     {
  con.close();
  System.out.println("Conexion cerrada...");
     }
            catch( Exception e)
     {
  e.printStackTrace();
  System.out.println("Error al cerrar la conexion...");
     }
        }
    /*Esta funcion cierra la conexion*/
    public void closeStatement()
        {
            try
     {
  stmt.close();
  System.out.println("Statement cerrado...");
     }
            catch( Exception e)
     {
  e.printStackTrace();
  System.out.println("Error al cerrar el  statement...");
     }
        }
    /**Esta funcion nos permite ejecutar una consulta de tipo Update*/
    public void executeUpdate(String _Update)
        {
            try
     {
  stmt = con.createStatement();
  System.out.println("Creamos el statement...");
  stmt.executeUpdate(_Update);
  System.out.println("Executamos el update...");
  //stmt.close();
          System.out.println("Cerramos el statement...");
     }
            catch( Exception e)
     {
  e.printStackTrace();
  System.out.println("Error al cerrar el statement...");
                closeStatement();
                closeConexion();
     }
        }
 
    /** Eejecuta una consulta */
    public ResultSet executeQuery(String _Query)
        {
            ResultSet rs = null;
            Statement stmt;
            try{
                stmt = con.createStatement();
                System.out.println("Creamos el statement...");
                rs = stmt.executeQuery(_Query);
                System.out.println("Executamos el Query...y almacenamos en el ResutlSet");
                //stmt.close();
                System.out.println("Cerramos el statement...");
            }
            catch( Exception e)
            {
                e.printStackTrace();
                System.out.println("Error al cerrar el statement...");
                closeStatement();
                closeConexion();
     }
            return rs;
        }
}
/*Fin de archivo ConexionBD.java*/
 
 


Do you Yahoo!?
Yahoo! Domains - Claim yours for only $14.70/year

Re: a big question

From
Oliver Jowett
Date:
Dam Avalos wrote:
> Hi!
> I have a big problem with the postgress driver, and i hope you can help
> me, i´m programming with java, and java has a method name
> Class.forName() that ask for the postgress driver... I send you the
> archive ConexionBD.java, and i hope you can help me, because when i run
> the program it says that it can´t get the driver, or found the driver,
> or something like that, so, well if you can help me i´ll be very
> gratefull with you, thanks a lot

Without more detail it's hard to be sure, but the most likely problem is
that the PostgreSQL JDBC driver is not in your classpath. See
http://www.postgresql.org/docs/7.4/static/jdbc.html#JDBC-CLASSPATH

-O