title: Google Cloud SQL JDBC Socket Facrory UnknownHostException: google
body: <p>I want to connect to Google Cloud SQL database using JDBC Socket Factory from a Spring 4 Maven application running in Kubernetes container.</p>
  
  <p>The pom.xml has:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;postgresql&lt;/groupId&gt;
      &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
      &lt;version&gt;8.4-702.jdbc4&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;com.google.cloud.sql&lt;/groupId&gt;
      &lt;artifactId&gt;postgres-socket-factory&lt;/artifactId&gt;
      &lt;version&gt;1.0.14&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>In applicationContext.xml:</p>
  
  <pre><code>&lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;  
      &lt;property name="driverClassName" value="org.postgresql.Driver"&gt;&lt;/property&gt;  
      &lt;property name="url" value="jdbc:postgresql://google/mydb?cloudSqlInstance=myinstance&amp;amp;socketFactory=com.google.cloud.sql.postgres.SocketFactory;"&gt;&lt;/property&gt;  
      &lt;property name="username" value="postgres"&gt;&lt;/property&gt;  
      &lt;property name="password" value="passwd"&gt;&lt;/property&gt;  
  &lt;/bean&gt; 
  </code></pre>
  
  <p>I have GOOGLE_APPLICATION_CREDENTIALS environment variable with service account details to access cloud sql.</p>
  
  <p>But I'm getting following exception:</p>
  
  <pre><code>Caused by: org.hibernate.exception.JDBCConnectionException: Could not open connection
          at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:131)
          at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
          at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
          at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1395)
          at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:59)
          ... 100 common frames omitted
  Caused by: org.postgresql.util.PSQLException: The connection attempt failed.
          at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:150)
          at org.postgresql.jdbc2.AbstractJdbc2Connection.&lt;init&gt;(AbstractJdbc2Connection.java:125)
          at org.postgresql.jdbc4.Jdbc4Connection.&lt;init&gt;(Jdbc4Connection.java:24)
          at org.postgresql.Driver.makeConnection(Driver.java:393)
          at java.sql.DriverManager.getConnection(DriverManager.java:664)
          at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:154)
          at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:297)
          ... 105 common frames omitted
  Caused by: java.net.UnknownHostException: google
          at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
          at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
          at java.net.Socket.connect(Socket.java:589)
          at java.net.Socket.connect(Socket.java:538)
          at java.net.Socket.&lt;init&gt;(Socket.java:434)
          at java.net.Socket.&lt;init&gt;(Socket.java:211)
          at org.postgresql.core.PGStream.&lt;init&gt;(PGStream.java:62)
          at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:76) 
  </code></pre>
  
  <p>What could be missing here?</p>