views:

52

answers:

2

Could someone help me or suggest a solution? I want to connect from a computer that has firewall to other where the postgres server run. The problem is that computer (client) has a firewall and I have not access to configure it, or open ports, ping does not respond. The computer (server) where PostgreSQL has open ports but I can not connect to it from another because of firewall. I can only access the computer through proxy. How I could with Java programming access remotely through proxy to postgres forgetting firewall? Java has a connection with proxies. But I dont now how put together with postgres connection. Thank you all. the same text in Spanish, sorry for bad English

Me podría ayudar alquien o sugerir la solución? Yo quiero conectarse desde ordenador que tiene firewall a servidor donde esta postgres. El problema esta que ordenador (cliente) tiene firewall y yo no tengo acceso para configurar a el, o abrir puertos, ping no contesta. El ordenador (servidor) donde esta postgre tiene abiertos puertos pero no puedo conectarme a el desde otro por causa de firewall. Solo puedo acceder a ordenador a través de proxy. Como podría programando con Java acceder remotamente a través de proxy a postgres pasando el firewall? Java tiene conexión con proxys. Pero no se como juntar con conexión a postgres. Gracias a todos.

        System.getProperties().put( "proxySet", "true" );
        System.getProperties().put( "proxyHost", "67.210.82.198" );
        System.getProperties().put( "proxyPort", "80" );

        URL validateURL = new URL("http://domain.com");
        URLConnection urlConnection = validateURL.openConnection();

        //how put together ???

        Class.forName("org.postgresql.Driver");
        Connection connection =  DriverManager.getConnection("jdbc:postgresql://ipPublica:5432/DataBase","user", "pass"); 
+1  A: 

Try

System.setProperty("http.proxyHost", "67.210.82.198");
System.setPropery("http.proxyPort", "80");

String url = "jdbc:postgresql://host:port/database";
Properties props = new Properties();
props.setProperty("user","myUsername");
props.setProperty("password","myPassword");
props.setProperty("ssl","true");

Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection(url, props);

For more, see java networking & proxies.

Zaki
Thank you very much friend on monday will test with firewall, now i test locally (postgres server) and it work ;) Thanks
ispan
A: 

I have a problem now ... With this code I got to connect to postgres en server machine, but it fails in client machine whith firewall.

//free public proxy finded in google.com

    System.setProperty("http.proxyHost", "189.19.44.164");
        System.setProperty("http.proxyPort", "3128");

        String url = "jdbc:postgresql://ipPublica:5432/DataBaseName";
        Properties props = new Properties();
        props.setProperty("user","User");
        props.setProperty("password","Pass");

        Class.forName("org.postgresql.Driver");

        Connection  connection = DriverManager.getConnection(url, props);

fails in client machine whith firewall With that error

org.postgresql.util.PSQLException: Connection refused. Verify that the hostname and port are correct and that the postmaster is accepting TCP / IP. at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl (ConnectionFactoryImpl.java: 136) at org.postgresql.core.ConnectionFactory.openConnection (ConnectionFactory.java: 66) at org.postgresql.jdbc2.AbstractJdbc2Connection. (AbstractJdbc2Connection.java: 125) at org.postgresql.jdbc3.AbstractJdbc3Connection. (AbstractJdbc3Connection.java: 30) at org.postgresql.jdbc3g.AbstractJdbc3gConnection. (AbstractJdbc3gConnection.java: 22) at org.postgresql.jdbc4.AbstractJdbc4Connection. (AbstractJdbc4Connection.java: 30) at org.postgresql.jdbc4.Jdbc4Connection. (Jdbc4Connection.java: 24) at org.postgresql.Driver.makeConnection (Driver.java: 393) at org.postgresql.Driver.connect (Driver.java: 267)

ispan