Thread: connectivity problem

connectivity problem

From
adp adp
Date:
Here is the classpath :
exportCLASSPATH=/root/j2sdk1.4.2/bin/test1.java:/root/j2sdk_nb/j2sdk1.4.2/jre/lib/ext/pg73jdbc3.jar:.


and here is the code:

import java.sql.*;
class test2{
  public static void main (String args[]) {


     try{


         Class.forName("org.postgresql.Driver");
        // DriverManager.registerDriver(new (Driver));




      String url="jdbc:postgresql:test";
      Connection con =
DriverManager.getConnection(url, "postgres", "");
      Statement stm= con.createStatement();


stm.setQueryTimeout(10);
ResultSet rs = stm.executeQuery("select col1 from
test1");


rs.next();


System.out.println(rs.getString(1));
}catch(ClassNotFoundException  e) {




 System.out.println("Exception");
 System.out.println(e.toString());
}
 catch(SQLException e) {




 System.out.println("Exception");
 System.out.println(e.toString());
}
}
}


and here is the error I receive :

Exception
The connection attempt failed because Exception:
java.net.UnknownHostException: localhost
Stack Trace:

java.net.UnknownHostException: localhost
        at
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:153)
        at java.net.Socket.connect(Socket.java:452)
        at java.net.Socket.connect(Socket.java:402)
        at java.net.Socket.<init>(Socket.java:309)
        at java.net.Socket.<init>(Socket.java:124)
        at
org.postgresql.PG_Stream.<init>(PG_Stream.java:38)
        at
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Connection.java:160)
        at
org.postgresql.Driver.connect(Driver.java:122)
        at
java.sql.DriverManager.getConnection(DriverManager.java:512)
        at
java.sql.DriverManager.getConnection(DriverManager.java:171)
        at test2.main(test2.java:13)
End of Stack Trace



________________________________________________________________________
Yahoo! India Mobile: Download the latest polyphonic ringtones.
Go to http://in.mobile.yahoo.com

Re: connectivity problem

From
Kris Jurka
Date:

> and here is the error I receive :
>
> Exception
> The connection attempt failed because Exception:
> java.net.UnknownHostException: localhost
> Stack Trace:
>

Java cannot resolve the IP address for localhost.  This is a general
network configuration problem unrelated to postresql.  Please check your
/etc/hosts file, you should have a line like

127.0.0.1    localhost

in it.  You can test that this is working by trying to ping localhost and
verifying that it correctly resolves.  Another option would be to
explicitly specify the IP address in the connection url.

Kris Jurka