1

I try to connect from my Android app to my postgresql server running on Windows 7. Both is running on my computer with a special IP. I try

String url = "jdbc:postgresql://xx.xx.xx.xx:5432/postgis20";
connect = DriverManager.getConnection(url,"postgres","xxxx");

The app is running in a simulator on my pc. Connect contains after the procedure null and Exceiption I get is The connection attempt failed. So what I do wrong with the connection? If I try to connect via the SQL Shell everything is working fine and I use the same parameter. SSL is set to no.

I also tried to use instead of my ip localhost or 127.0.0.1 but that has the same result.

I changed the permission settings to allow the access to the internet. But now I get the following error: org.postgresql.util.PSQLException: Something unusual has occured to cause the driver to fail. Please report this exception.

1 Answer 1

4

To use jdbc on Android it is necessary to use the StrictMode. That can be done by using the following code lines:

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Sign up to request clarification or add additional context in comments.

1 Comment

Hi , where do I place this code , in connection class or MainActivity ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.