[Pgsql-ayuda] JDBC

From: hpl(at)mexico(dot)com
To: pgsql-ayuda(at)tlali(dot)iztacala(dot)unam(dot)mx
Subject: [Pgsql-ayuda] JDBC
Date: 2003-01-02 09:02:42
Message-ID: 200301020902.DAA03486@glupsis.acsinet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Holap !
Estoy empezando en postgres
Usando el siguiente programa de un manual de postgresql para probar el JDBC me
marca errores :-<

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:prueba","usuario1","");
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_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();
}
}
}
$ java myappjdbc
Enter a state code: AL
Exception caught.
java.lang.NullPointerException
java.lang.NullPointerException
at myappjdbc.<init>(myappjdbc.java:19)
at myappjdbc.main(myappjdbc.java:36)
Lo probe en Postgresql 7.1 en RH 6.2
Grapcias y Feliz Ao !

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message hpl 2003-01-02 09:06:26 [Pgsql-ayuda] JDBC
Previous Message Alejandro Rivadeneira 2003-01-01 23:17:29 [Pgsql-ayuda] PostgreSQL - Interesante entrevista