[Pgsql-ayuda] JDBC si jalar

From: "Hugo Pablo Leyva" <hpl(at)colima(dot)com>
To: pgsql-ayuda(at)tlali(dot)iztacala(dot)unam(dot)mx
Subject: [Pgsql-ayuda] JDBC si jalar
Date: 2003-05-22 02:26:51
Message-ID: 20030522022652.24671.qmail@mexico.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

¡ Hola lista !

Estoy probando postgresql con diferentes
API's.
Las de C, C++ me funcionan bien pero tengo
problemas con JDBC

Pruebo con el siguiente programa:

import java.io.*;
import java.sql.*;
public class myappjdbc
{
Connection conn;
Statement stmt;
String state_code;

public myappjdbc() throws
ClassNotFoundException,
FileNotFoundException, IOException,
SQLException
{

Class.forName("org.postgresql.Driver");

conn =
DriverManager.getConnection("jdbc:postgresql:stores7","hpl","");
System.out.println("DEMO JDBC
");
System.out.print("Enter a
state code: ");
System.out.flush();
BufferedReader r = new
BufferedReader(new
InputStreamReader(System.in));
state_code=r.readLine();

ResultSet res =
stmt.executeQuery("SELECT sname FROM state
WHERE code = '" + state_code + "'");

if(res!=null)
while(res.next())
{
String
state_name = res.getString(1);

System.out.println(state_code + "=" +
state_name);
}

res.close();
stmt.close();
conn.close();
}
public static void main(String args[])
{
try
{
myappjdbc test = new
myappjdbc();
}
catch (Exception exc)
{

System.err.println("Exception caught.\n"+exc);
exc.printStackTrace();
}
}
}
Al correr me marca:
$ java myappjdbc
DEMO JDBC
Enter a state code: CA
Exception caught.
java.lang.NullPointerException
java.lang.NullPointerException
at myappjdbc.<init>(myappjdbc.java:20)
at myappjdbc.main(myappjdbc.java:37)
La variable CLASSPATH es
CLASSPATH=/usr/share/pgsql/jdbc7.0-1.1.jar:/usr/share/pgsql/jdbc7.1-1.2.jar:.
USO RH 7.2 y postgresql 7.1.3-2
¿ Donde puede estar el error ?

¡ Grapcias !

--

Powered by Outblaze

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Alvaro Herrera 2003-05-22 02:55:52 Re: [Pgsql-ayuda] Configurar postgres antes de compilarlo???
Previous Message Leonardo Boet Sánchez 2003-05-21 23:28:50 [Pgsql-ayuda] Configurar postgres antes de compilarlo???