Cannot connect to Cloud SQL with Java SocketFactory Library












-1















This is a duplicate question I made on Cloud SQL google group discuss forum: https://groups.google.com/forum/#!topic/google-cloud-sql-discuss/qYmjvfH0MdI



I'm using Cloud Dataflow to run some pipelines using Cloud SQL as a sink in my personal account. After the pipeline is executed, I want to make a connection to Cloud SQL to run a delete statement. I can't run deletes with JdbcIO (only selects and inserts). Even though I can connect to Cloud SQL with JdbcIO, I cannot connect to it using plain Jdbc.



Below is the code I'm using to connect to my instance



static void cleanUpPipeline() {
String jdbcUrl = String.format(
"jdbc:postgresql://google/%s?cloudSqlInstance=%s"
+ "&socketFactory=com.google.cloud.sql.postgres.SocketFactory",
"xxxxxx",
"xxxxxx");

try {
Class.forName("org.postgresql.Driver");
Connection connection = DriverManager.getConnection(jdbcUrl, "xxxxxx", "xxxxxx");
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
}
}


My pom.xml has the following dependencies:



<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>postgres-socket-factory</artifactId>
<version>1.0.11</version>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
</dependency>


The error I receive is:




INFO: Connecting to Cloud SQL instance [xxxxxxxxx] via ssl socket. nov
13, 2018 2:53:49 PM com.google.cloud.sql.core.SslSocketFactory
getInstance



INFO: First Cloud SQL connection, generating RSA key pair. nov 13,
2018 2:53:51 PM com.google.cloud.sql.core.SslSocketFactory
fetchInstanceSslInfo



INFO: Obtaining ephemeral certificate for Cloud SQL instance [xxxxxx].
nov 13, 2018 2:53:54 PM com.google.cloud.sql.core.SslSocketFactory
createAndConfigureSocket



INFO: Connecting to Cloud SQL instance [xxxxxxxx] on IP [xxxxxxx]
org.postgresql.util.PSQLException: Connection to google:5432 refused.
Check that the hostname and port are correct and that the postmaster
is accepting TCP/IP connections.




I believe I'm doing everything right here. Can anyone help me?










share|improve this question



























    -1















    This is a duplicate question I made on Cloud SQL google group discuss forum: https://groups.google.com/forum/#!topic/google-cloud-sql-discuss/qYmjvfH0MdI



    I'm using Cloud Dataflow to run some pipelines using Cloud SQL as a sink in my personal account. After the pipeline is executed, I want to make a connection to Cloud SQL to run a delete statement. I can't run deletes with JdbcIO (only selects and inserts). Even though I can connect to Cloud SQL with JdbcIO, I cannot connect to it using plain Jdbc.



    Below is the code I'm using to connect to my instance



    static void cleanUpPipeline() {
    String jdbcUrl = String.format(
    "jdbc:postgresql://google/%s?cloudSqlInstance=%s"
    + "&socketFactory=com.google.cloud.sql.postgres.SocketFactory",
    "xxxxxx",
    "xxxxxx");

    try {
    Class.forName("org.postgresql.Driver");
    Connection connection = DriverManager.getConnection(jdbcUrl, "xxxxxx", "xxxxxx");
    } catch (SQLException | ClassNotFoundException e) {
    e.printStackTrace();
    }
    }


    My pom.xml has the following dependencies:



    <dependency>
    <groupId>com.google.cloud.sql</groupId>
    <artifactId>postgres-socket-factory</artifactId>
    <version>1.0.11</version>
    </dependency>

    <dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>42.2.5</version>
    </dependency>


    The error I receive is:




    INFO: Connecting to Cloud SQL instance [xxxxxxxxx] via ssl socket. nov
    13, 2018 2:53:49 PM com.google.cloud.sql.core.SslSocketFactory
    getInstance



    INFO: First Cloud SQL connection, generating RSA key pair. nov 13,
    2018 2:53:51 PM com.google.cloud.sql.core.SslSocketFactory
    fetchInstanceSslInfo



    INFO: Obtaining ephemeral certificate for Cloud SQL instance [xxxxxx].
    nov 13, 2018 2:53:54 PM com.google.cloud.sql.core.SslSocketFactory
    createAndConfigureSocket



    INFO: Connecting to Cloud SQL instance [xxxxxxxx] on IP [xxxxxxx]
    org.postgresql.util.PSQLException: Connection to google:5432 refused.
    Check that the hostname and port are correct and that the postmaster
    is accepting TCP/IP connections.




    I believe I'm doing everything right here. Can anyone help me?










    share|improve this question

























      -1












      -1








      -1








      This is a duplicate question I made on Cloud SQL google group discuss forum: https://groups.google.com/forum/#!topic/google-cloud-sql-discuss/qYmjvfH0MdI



      I'm using Cloud Dataflow to run some pipelines using Cloud SQL as a sink in my personal account. After the pipeline is executed, I want to make a connection to Cloud SQL to run a delete statement. I can't run deletes with JdbcIO (only selects and inserts). Even though I can connect to Cloud SQL with JdbcIO, I cannot connect to it using plain Jdbc.



      Below is the code I'm using to connect to my instance



      static void cleanUpPipeline() {
      String jdbcUrl = String.format(
      "jdbc:postgresql://google/%s?cloudSqlInstance=%s"
      + "&socketFactory=com.google.cloud.sql.postgres.SocketFactory",
      "xxxxxx",
      "xxxxxx");

      try {
      Class.forName("org.postgresql.Driver");
      Connection connection = DriverManager.getConnection(jdbcUrl, "xxxxxx", "xxxxxx");
      } catch (SQLException | ClassNotFoundException e) {
      e.printStackTrace();
      }
      }


      My pom.xml has the following dependencies:



      <dependency>
      <groupId>com.google.cloud.sql</groupId>
      <artifactId>postgres-socket-factory</artifactId>
      <version>1.0.11</version>
      </dependency>

      <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <version>42.2.5</version>
      </dependency>


      The error I receive is:




      INFO: Connecting to Cloud SQL instance [xxxxxxxxx] via ssl socket. nov
      13, 2018 2:53:49 PM com.google.cloud.sql.core.SslSocketFactory
      getInstance



      INFO: First Cloud SQL connection, generating RSA key pair. nov 13,
      2018 2:53:51 PM com.google.cloud.sql.core.SslSocketFactory
      fetchInstanceSslInfo



      INFO: Obtaining ephemeral certificate for Cloud SQL instance [xxxxxx].
      nov 13, 2018 2:53:54 PM com.google.cloud.sql.core.SslSocketFactory
      createAndConfigureSocket



      INFO: Connecting to Cloud SQL instance [xxxxxxxx] on IP [xxxxxxx]
      org.postgresql.util.PSQLException: Connection to google:5432 refused.
      Check that the hostname and port are correct and that the postmaster
      is accepting TCP/IP connections.




      I believe I'm doing everything right here. Can anyone help me?










      share|improve this question














      This is a duplicate question I made on Cloud SQL google group discuss forum: https://groups.google.com/forum/#!topic/google-cloud-sql-discuss/qYmjvfH0MdI



      I'm using Cloud Dataflow to run some pipelines using Cloud SQL as a sink in my personal account. After the pipeline is executed, I want to make a connection to Cloud SQL to run a delete statement. I can't run deletes with JdbcIO (only selects and inserts). Even though I can connect to Cloud SQL with JdbcIO, I cannot connect to it using plain Jdbc.



      Below is the code I'm using to connect to my instance



      static void cleanUpPipeline() {
      String jdbcUrl = String.format(
      "jdbc:postgresql://google/%s?cloudSqlInstance=%s"
      + "&socketFactory=com.google.cloud.sql.postgres.SocketFactory",
      "xxxxxx",
      "xxxxxx");

      try {
      Class.forName("org.postgresql.Driver");
      Connection connection = DriverManager.getConnection(jdbcUrl, "xxxxxx", "xxxxxx");
      } catch (SQLException | ClassNotFoundException e) {
      e.printStackTrace();
      }
      }


      My pom.xml has the following dependencies:



      <dependency>
      <groupId>com.google.cloud.sql</groupId>
      <artifactId>postgres-socket-factory</artifactId>
      <version>1.0.11</version>
      </dependency>

      <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <version>42.2.5</version>
      </dependency>


      The error I receive is:




      INFO: Connecting to Cloud SQL instance [xxxxxxxxx] via ssl socket. nov
      13, 2018 2:53:49 PM com.google.cloud.sql.core.SslSocketFactory
      getInstance



      INFO: First Cloud SQL connection, generating RSA key pair. nov 13,
      2018 2:53:51 PM com.google.cloud.sql.core.SslSocketFactory
      fetchInstanceSslInfo



      INFO: Obtaining ephemeral certificate for Cloud SQL instance [xxxxxx].
      nov 13, 2018 2:53:54 PM com.google.cloud.sql.core.SslSocketFactory
      createAndConfigureSocket



      INFO: Connecting to Cloud SQL instance [xxxxxxxx] on IP [xxxxxxx]
      org.postgresql.util.PSQLException: Connection to google:5432 refused.
      Check that the hostname and port are correct and that the postmaster
      is accepting TCP/IP connections.




      I believe I'm doing everything right here. Can anyone help me?







      google-cloud-platform google-cloud-sql






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 18:27









      d4nielfr4ncod4nielfr4nco

      9518




      9518
























          1 Answer
          1






          active

          oldest

          votes


















          0














          At the end, it was a firewall issue. I couldn't access port 3307 from inside the firewall, which is the port Cloud SQL Proxy uses. I believe the Java SocketFactory library also needs to use that port.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306610%2fcannot-connect-to-cloud-sql-with-java-socketfactory-library%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            At the end, it was a firewall issue. I couldn't access port 3307 from inside the firewall, which is the port Cloud SQL Proxy uses. I believe the Java SocketFactory library also needs to use that port.






            share|improve this answer




























              0














              At the end, it was a firewall issue. I couldn't access port 3307 from inside the firewall, which is the port Cloud SQL Proxy uses. I believe the Java SocketFactory library also needs to use that port.






              share|improve this answer


























                0












                0








                0







                At the end, it was a firewall issue. I couldn't access port 3307 from inside the firewall, which is the port Cloud SQL Proxy uses. I believe the Java SocketFactory library also needs to use that port.






                share|improve this answer













                At the end, it was a firewall issue. I couldn't access port 3307 from inside the firewall, which is the port Cloud SQL Proxy uses. I believe the Java SocketFactory library also needs to use that port.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 '18 at 18:32









                d4nielfr4ncod4nielfr4nco

                9518




                9518






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306610%2fcannot-connect-to-cloud-sql-with-java-socketfactory-library%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Xamarin.form Move up view when keyboard appear

                    Post-Redirect-Get with Spring WebFlux and Thymeleaf

                    Anylogic : not able to use stopDelay()