Skip site navigation (1) Skip section navigation (2)

a big question

From: Dam Avalos <aleidam8(at)yahoo(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: a big question
Date: 2004-05-20 22:54:20
Message-ID: 20040520225420.92406.qmail@web11906.mail.yahoo.com (view raw or flat)
Thread:
Lists: pgsql-jdbc
Hi!
I have a big problem with the postgress driver, and i hope you can help me, im 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 cant get the driver, or found the driver, or something like that, so, well if you can help me ill be very gratefull with you, thanks a lot 
 
/*
ARCHIVO: ConexionBD.java
AUTOR:   Daniela Avalos Monroy
         aleidam8(at)yahoo(dot)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

Responses

pgsql-jdbc by date

Next:From: Oliver JowettDate: 2004-05-20 22:54:43
Subject: Re: Queries with large ResultSets
Previous:From: Andrea AimeDate: 2004-05-20 20:56:41
Subject: Re: Queries with large ResultSets

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group