From: | "Miguel Angel Martin" <miguelangel(dot)java(at)ozu(dot)es> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org(dot) |
Subject: | I can't connect to a database from application |
Date: | 2003-03-31 22:21:48 |
Message-ID: | web-201221404@ozu.es |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
I can't connect to a database from application but yes
from IDE!.
I use: Cygwin-postgresql 7.3.2 Win98 Netbeans 3.4 and
JDK 1.4
I Launch postgresql with the -i option to enable TCP/IP
connections.
No problem to connect to de database by the database
option of the Runtime panel in Netbeans. I can access all
the tables, etc. But, I can't connect to the database
from an application (inside Netbeans). The source, to
check the database access, is:
import java.sql.*;
public class postgres {
public static void main(String[] args) {
System.out.println("trying...");
try {
String url = new
String("jdbc:postgresql:net//localhost:5432/basicportal");
String usr = new String("xxxx");
String pwd = new String(""); //postgres
usr/password
System.out.println("finding driver...");
Class.forName("org.sourceforge.jxdbcon.JXDBConDriver");
System.out.println("creating
driverManager...");
Connection db =
DriverManager.getConnection(url,usr,pwd);
System.out.println("creating statement...");
Statement st = db.createStatement();
System.out.println("executing query...");
ResultSet rs = st.executeQuery("select * from
base_content");
System.out.println("looping data...");
while(rs.next()) {
System.out.print("Column 1 returned ");
System.out.println(rs.getString(1));
}
System.out.println("loop finished, closing
connection");
rs.close();
st.close();
}
catch( Exception e) {
System.out.println("Exception encountered: "
+ e);
}
}
}
And this is the output of the Output Window:
trying...
finding driver...
creating driverManager...
Exception encountered: java.lang.NullPointerException
And the output of postgre in the Cygwin Window:
"LOG: pq_recvbuf: unexpected EOF on client connection"
I'd put posgresql.jar in
netbeans\lib\ext
myapplication\WEB-INF\lib
and, later, in
tomcat404\classes
netbeans\tomcat404\lib
Can anybody help me?
Thanks !
Miguel A. Martin
Malaga - Spain
--------------------------------------------------
Nuevo Depósito a 1 mes 6% TAE, contrátalo:
http://ingdirect.ozu.es
--------------------------------------------------
Correo enviado desde http://www.ozu.es
From | Date | Subject | |
---|---|---|---|
Next Message | Dave Cramer | 2003-03-31 23:39:34 | Re: setCatalog() |
Previous Message | Patrik Lundgren | 2003-03-31 21:04:23 | Re: setCatalog() |