[Pgsql-ayuda] JDBC si jalar

Hugo Pablo Leyva hpl@colima.com
Thu, 22 May 2003 10:26:51 +0800


¡ 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