Обсуждение: Newbie: connecting from windows to Linux: how-to?
I'm sure this question must have been asked before but I cannot find it in the archives. If this is the wrong ML to ask please let me know. I have PostgreSQL running on a Linux box and now I would like to build a Java GUI tool to access/modify the data. I'm guessing the first thing I need to learn how to do in Java is how to connect from the windows machine to the Linux pg DB. I've read http://jdbc.postgresql.org/doc.html about downloading and installing the JDBC driver but I don't see any instructions relating on how to do this in windows ... Can someone explain to me or point me to a document that explains the steps I need to take in order to establish a connection in Java from windows to PostgreSQL running on a linux box? Thanks! Jc
Laszlo Hornyak wrote: > > Check your $CLASSPATH, you need a postgresql.jar in it. Where do I get that jar from? I was able to download a "pgjdbc2.jar" which is supposed to be the JDBC driver from the PostgreSQl site but I could not find any postgresql.jar file anywhere .... Also ... the install instructions call for "make" and stuff. I'm on Windows ... Jc
SHEVLAND, Joe wrote: > > You might want to look at a little primer I whipped up a while ago, but > it should be relevant still: > > http://www.j-elite.com/pgprimer Thanks! It was very useful. I know have things sort of running ... I just can't connect. I think the problem is in the connect string. I have this, is it syntactically correct? c = DriverManager.getConnection("jdbc:postgresql://192.168.254.14:5432/JC", "postgres", ""); I am assuming the password is null since I don't remember setting one. Also the following connect string works (locally) in PHP, without a password: $conn = pg_connect("dbname=JC user=postgres"); Thanks for the help! Jc PS I am receiving all the replies I send to the list as private emails. But I don't receive the any list emails ... is everyone sending me private emails or did I not register properly with the list?
SHEVLAND, Joe wrote: >You might want to look at a little primer I whipped up a while ago, but >it should be relevant still: >http://www.j-elite.com/pgprimer Thanks! It was very useful. I know have things sort of running ... I just can't connect. I think the problem is in the connect string. I have this, is it syntactically correct? c = DriverManager.getConnection("jdbc:postgresql://192.168.254.14:5432/JC", "postgres", ""); I am assuming the password is null since I don't remember setting one. Also the following connect string works (locally) in PHP, without a password: $conn = pg_connect("dbname=JC user=postgres"); Thanks for the help! Jc PS I am receiving all the replies I send to the list as private emails. But I don't receive the any list emails ... is everyone sending me private emails or did I not register properly with the list?
Laszlo Hornyak wrote: > As much as I know Pg doesn`t build on windows. Maybe try it on linux. > > to check a jar file: > jar tf jarfile.jar > if you see the class file, it is ok. I'm using Pg on Linux but Java on Windows. The jar file seems fine using the command you gave. I did check that Pg is running with IP on ... $ netstat -an | grep 5432 | grep LISTEN unix 2 [ ACC ] STREAM LISTENING 1347 /tmp/.s.PGSQL.5432 I tried the test program suggested in the link given by Joe Shevland and everything seems to be fine except for my connection string. I have tried these various connection strings: Connection c = null; c1 = DriverManager.getConnection("jdbc:postgresql://192.168.254.14/JC","postgres",""); c2 = DriverManager.getConnection("jdbc:postgresql://192.168.254.14:5432/JC","postgres",""); And get this error for both strings: Checking if Driver is registered with DriverManager. Couldn't find the driver! Let's print a stack trace, and exit. java.lang.ClassNotFoundException: org.postgresql.Driver at java.net.URLClassLoader$1.run(URLClassLoader.java:198) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:186) at java.lang.ClassLoader.loadClass(ClassLoader.java:299) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265) at java.lang.ClassLoader.loadClass(ClassLoader.java:255) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:140) at Example1.main(Example1.java:10) Jc
Laszlo Hornyak wrote: > > Simply java doesn`t find the driver classes. > What does the following say? Oops ... I posted the wrong ouput ... the driver class is being found (I think, since it is being registered). Maye I need InstanceOf()? Here is the error message I get: D:\java>java -cp .;pgjdbc2.jar Example1 Checking if Driver is registered with DriverManager. Registered the driver ok, so let's make a connection. Couldn't connect: print out a stack trace and exit. Connection refused. Check that the hostname and port is correct, and that the postmaster is running with the -i flag, which enables TCP/IP networking. at org.postgresql.Connection.openConnection(Connection.java:141) at org.postgresql.Driver.connect(Driver.java:149) at java.sql.DriverManager.getConnection(DriverManager.java:512) at java.sql.DriverManager.getConnection(DriverManager.java:171) at Example1.main(Example1.java:26) > set %CLASSPATH CLASSPATH=.;d\j2sdk1.4.1 Jc
On Wed, 9 Oct 2002, Jean-Christian Imbeault wrote: > I did check that Pg is running with IP on ... > > $ netstat -an | grep 5432 | grep LISTEN > unix 2 [ ACC ] STREAM LISTENING 1347 /tmp/.s.PGSQL.5432 But this means it's *not* running with IP -- it's running with UNIX sockets, which is how it handles non-network requests. If you try "telnet serverhostname 5432", I would expect you'd get a connection refused message. Aaron