Holap Lista !
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 con RH 6.2 y Postgresql 7.2 con RH 7.3
Grapcias y Feliz Ao !