From: Dam Avalos <aleidam8@yahoo.com>
To: pgsql-jdbc@postgresql.org
Subject: a big question
Date: Thu, 20 May 2004 15:54:20 -0700 (PDT)
Message-ID: <20040520225420.92406.qmail@web11906.mail.yahoo.com> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: aleidam8@yahoo.com
Subject: Re: a big question
In-Reply-To: <20040520225420.92406.qmail@web11906.mail.yahoo.com>
References: <20040520225420.92406.qmail@web11906.mail.yahoo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox