title: Not able to connect to Cloud SQL using Java SocketFactory Library
body: <p>I am trying to connect to Cloud SQL ( Mysql ) using my java code. I am getting the below error - </p>
  
  <pre><code>com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create socket factory 'com.google.cloud.sql.mysql.SocketFactory' due to underlying exception: 
          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
          at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:185)
          at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:210)
          at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:124)
          at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
  Caused by: java.lang.ClassNotFoundException: com.google.cloud.sql.mysql.SocketFactory
  </code></pre>
  
  <p>Here is my code - </p>
  
  <pre><code>package utils
  import java.sql.DriverManager
  import java.sql.Connection
  import scala.collection.mutable.ListBuffer
  import entity.AnalyticFieldEntity
  import compute.driver.AnalyticTools
  import entity.ErrorHandlingEntity
  
  object ScalaDbConnect {
  
      def getAnalyticBatchMap(toolId : Int, paramMap: Map[String, String]): Map[String, Int] = {
      val methodName = "getAnalyticBatchMap"
      val errorMode = paramMap.get("mode")+"("+paramMap.get("analyticSource")+")"
  
      val dbTuple = DbPropertiesReader.getDbProperties()
  
  
        val databaseName = dbTuple._3
        val instanceConnectionName = dbTuple._4
        val username= dbTuple._1
        val password= dbTuple._2
  
  
      var connection: Connection = null
      val analyticMap = collection.mutable.Map.empty[String, Int]
      try {
        //[START doc-example]
        val jdbcUrl = String.format(
          "jdbc:mysql://google/%s?cloudSqlInstance=%s&amp;"
              + "socketFactory=com.google.cloud.sql.mysql.SocketFactory", databaseName, instanceConnectionName);
  
        println(jdbcUrl);
        //Class.forName("com.mysql.jdbc.GoogleDriver");
        val connection = DriverManager.getConnection(jdbcUrl, username, password);
        println(connection);
  
      //[END doc-example]
  
        try 
        {
  
          val statement = connection.createStatement()
          val resultSet = statement.executeQuery("SELECT omnitureColumnHeader.columnHeaderId, case when analyticFieldMap.isTag = 1 then concat(\"tag_\",analyticFieldMap.entityField) else  " +
          "analyticFieldMap.entityField  end as entityField FROM omnitureColumnHeader INNER JOIN analyticFieldMap ON " +
          "analyticFieldMap.analyticFieldBatch=omnitureColumnHeader.columnHeaderValue where analyticFieldMap.toolId = " + toolId);
  
          System.out.println("resultSet: 2" + statement);
          System.out.println("statement: 2" + resultSet);
  
  
          while (resultSet.next()) {
  
                      System.out.println("inside the content loop: 2");
            analyticMap += resultSet.getString("entityField") -&gt; resultSet.getInt("columnHeaderId")
  
  
             }
  
  
          System.out.println("analyticMap: 2" + analyticMap);
      }
        catch
        {
           case _: Throwable =&gt; println("Got some other kind of exception")
        }
  
  
      } catch {
        case e: Exception =&gt;
                 val errorHandlingEntity = new ErrorHandlingEntity()
                    errorHandlingEntity.Mode=errorMode
                    errorHandlingEntity.Tool=paramMap.get("tool").toString()
                    errorHandlingEntity.Message="DB Connection Issue"
                    errorHandlingEntity.Trace=e.printStackTrace().toString()
                    errorHandlingEntity.Source = "Spark"
                    errorHandlingEntity.YarnAppId=paramMap.get("appID").toString()
                    errorHandlingEntity.MethodName=methodName
                    errorHandlingEntity.ReThrow = true
                    errorHandlingEntity.CurrentException=e
  
                    ErrorHandlingFramework.HandleException(errorHandlingEntity)
      }
      connection.close()
  
      analyticMap.toMap
  
    }
  }
  </code></pre>
  
  <p>I have added the below details in my POM.XML</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;com.google.cloud.sql&lt;/groupId&gt;
      &lt;artifactId&gt;mysql-socket-factory&lt;/artifactId&gt;
      &lt;version&gt;1.0.3&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>Here is the complete POM.XML - <a href="https://pastebin.com/jvxSBZMX" rel="nofollow noreferrer">https://pastebin.com/jvxSBZMX</a></p>
  
  <p>I am trying to connect to Google Cloud SQL using my scala code and i am using the JAVA API(S). 
  The issue i am facing indicates, i am not able to access the correct class for the connection.</p>
  
  <p>Any help would be appreciated. </p>
  
  <p>Looking forward for the solution. </p>
  
  <p>Thanks,</p>