Class : Scala and Spark Live Training - 10 - Developing Scala applications

Hi I am unable to connect to MySql from Intellij with port no :3306. Below is the code

Code:-
package JDBC

/**

  • Original Author : Itversity
  • class : Scala and Spark Live Training - 10 - Developing Scala applications
  • Dt : 19:08:2019
    */
    // Import Packages
    import java.sql.DriverManager

// Create case class EmployeeCommission to create objects for the query results
// In Web applications objects will be created and transferred between layers of it.

case class EmployeesCommission(first_name: String,
last_name:String,
salary: Double,
commission_pct: Double){
override def toString():String ={
s"first_name: " + first_name + "last_name: " + last_name +
“;” + “commission amount” + getCommissionAmount()
}
def getCommissionAmount():Any = {
if (commission_pct == 0){
“Not Elligible”
}else salary * commission_pct

}
}

object CommissionAmount {
def main(args: Array[String]): Unit = {
val driver = “com.mysql.jdbc.Driver”
val host = “nn01.itversity.com
val port = “3306”
val db = “hr”
val url = “jdbc:mysql://nn01.itversity.com:3306/hr”
//val url = “jdbc:mysql://” + host + “:” + port + “/” + db
val username = “hr_ro”
val password =“itversity”

Class.forName(driver)
val connection = DriverManager.getConnection(url,username,password)
val statement = connection.createStatement()
val resultset = statement.executeQuery("SELECT first_name,last_name" +
"salary,commission_pct FROM employees")

// Functional way of processing resultset
Iterator.
  continually(resultset.next(),resultset).
  takeWhile(_._1).
  map(r =>{
    EmployeesCommission(
      r._2.getString("first_name"),
      r._2.getString("last_name"),
      r._2.getDouble("salary"),
      r._2.getDouble("commission_pct")
    )
  }).
  toList.
  foreach(println)

}

}

o/p—

“C:\Program Files\Java\jdk1.8.0_221\bin\java.exe” “-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.1.3\lib\idea_rt.jar=56504:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.1.3\bin” -Dfile.encoding=UTF-8 -classpath “C:\Program Files\Java\jdk1.8.0_221\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\rt.jar;C:\Users\Miku\IdeaProjects\Scala_Pratice\target\scala-2.11\classes;C:\Users\Miku.ivy2\cache\aopalliance\aopalliance\jars\aopalliance-1.0.jar;C:\Users\Miku.ivy2\cache\com.typesafe\config\bundles\config-1.3.4.jar;C:\Users\Miku.ivy2\cache\org.xerial.snappy\snappy-java\bundles\snappy-java-1.1.7.2.jar;C:\Users\Miku.ivy2\cache\org.lz4\lz4-java\jars\lz4-java-1.5.0.jar;C:\Users\Miku.ivy2\cache\org.apache.kafka\kafka-clients\jars\kafka-clients-2.1.1.jar;C:\Users\Miku.ivy2\cache\com.github.luben\zstd-jni\jars\zstd-jni-1.3.7-1.jar;C:\Users\Miku.ivy2\cache\org.typelevel\macro-compat_2.11\jars\macro-compat_2.11-1.1.1.jar;C:\Users\Miku.ivy2\cache\org.typelevel\machinist_2.11\jars\machinist_2.11-0.6.1.jar;C:\Users\Miku.ivy2\cache\org.spire-math\spire_2.11\jars\spire_2.11-0.13.0.jar;C:\Users\Miku.ivy2\cache\org.spire-math\spire-macros_2.11\jars\spire-macros_2.11-0.13.0.jar;C:\Users\Miku.ivy2\cache\org.scalanlp\breeze_2.11\jars\breeze_2.11-0.13.2.jar;C:\Users\Miku.ivy2\cache\org.scalanlp\breeze-macros_2.11\jars\breeze-macros_2.11-0.13.2.jar;C:\Users\Miku.ivy2\cache\org.apache.spark\spark-streaming_2.11\jars\spark-streaming_2.11-2.3.3.jar;C:\Users\Miku.ivy2\cache\org.apache.spark\spark-mllib_2.11\jars\spark-mllib_2.11-2.3.3.jar;C:\Users\Miku.ivy2\cache\org.apache.spark\spark-mllib-local_2.11\jars\spark-mllib-local_2.11-2.3.3.jar;C:\Users\Miku.ivy2\cache\org.apache.spark\spark-graphx_2.11\jars\spark-graphx_2.11-2.3.3.jar;C:\Users\Miku.ivy2\cache\net.sourceforge.f2j\arpack_combined_all\jars\arpack_combined_all-0.1.jar;C:\Users\Miku.ivy2\cache\net.sf.opencsv\opencsv\jars\opencsv-2.3.jar;C:\Users\Miku.ivy2\cache\com.github.rwl\jtransforms\jars\jtransforms-2.4.0.jar;C:\Users\Miku.ivy2\cache\com.github.fommil.netlib\core\jars\core-1.1.2.jar;C:\Users\Miku.ivy2\cache\com.chuusai\shapeless_2.11\bundles\shapeless_2.11-2.3.2.jar;C:\Users\Miku.ivy2\cache\xmlenc\xmlenc\jars\xmlenc-0.52.jar;C:\Users\Miku.ivy2\cache\xml-apis\xml-apis\jars\xml-apis-1.3.04.jar;C:\Users\Miku.ivy2\cache\xerces\xercesImpl\jars\xercesImpl-2.9.1.jar;C:\Users\Miku.ivy2\cache\oro\oro\jars\oro-2.0.8.jar;C:\Users\Miku.ivy2\cache\org.tukaani\xz\jars\xz-1.0.jar;C:\Users\Miku.ivy2\cache\org.spark-project.spark\unused\jars\unused-1.0.0.jar;C:\Users\Miku.ivy2\cache\org.sonatype.sisu.inject\cglib\jars\cglib-2.2.1-v20090111.jar;C:\Users\Miku.ivy2\cache\org.slf4j\slf4j-log4j12\jars\slf4j-log4j12-1.7.16.jar;C:\Users\Miku.ivy2\cache\org.slf4j\jul-to-slf4j\jars\jul-to-slf4j-1.7.16.jar;C:\Users\Miku.ivy2\cache\org.slf4j\jcl-over-slf4j\jars\jcl-over-slf4j-1.7.16.jar;C:\Users\Miku.ivy2\cache\org.scala-lang.modules\scala-xml_2.11\bundles\scala-xml_2.11-1.0.5.jar;C:\Users\Miku.ivy2\cache\org.scala-lang.modules\scala-parser-combinators_2.11\bundles\scala-parser-combinators_2.11-1.0.4.jar;C:\Users\Miku.ivy2\cache\org.scala-lang\scalap\jars\scalap-2.11.11.jar;C:\Users\Miku.ivy2\cache\org.scala-lang\scala-reflect\jars\scala-reflect-2.11.11.jar;C:\Users\Miku.ivy2\cache\org.scala-lang\scala-library\jars\scala-library-2.11.11.jar;C:\Users\Miku.ivy2\cache\org.scala-lang\scala-compiler\jars\scala-compiler-2.11.11.jar;C:\Users\Miku.ivy2\cache\org.roaringbitmap\RoaringBitmap\bundles\RoaringBitmap-0.5.11.jar;C:\Users\Miku.ivy2\cache\org.objenesis\objenesis\jars\objenesis-2.1.jar;C:\Users\Miku.ivy2\cache\org.mortbay.jetty\jetty-util\jars\jetty-util-6.1.26.jar;C:\Users\Miku.ivy2\cache\org.json4s\json4s-jackson_2.11\jars\json4s-jackson_2.11-3.2.11.jar;C:\Users\Miku.ivy2\cache\org.json4s\json4s-core_2.11\jars\json4s-core_2.11-3.2.11.jar;C:\Users\Miku.ivy2\cache\org.json4s\json4s-ast_2.11\jars\json4s-ast_2.11-3.2.11.jar;C:\Users\Miku.ivy2\cache\org.javassist\javassist\bundles\javassist-3.18.1-GA.jar;C:\Users\Miku.ivy2\cache\org.htrace\htrace-core\jars\htrace-core-3.0.4.jar;C:\Users\Miku.ivy2\cache\org.glassfish.jersey.media\jersey-media-jaxb\jars\jersey-media-jaxb-2.22.2.jar;C:\Users\Miku.ivy2\cache\org.glassfish.jersey.core\jersey-server\jars\jersey-server-2.22.2.jar;C:\Users\Miku.ivy2\cache\org.glassfish.jersey.core\jersey-common\jars\jersey-common-2.22.2.jar;C:\Users\Miku.ivy2\cache\org.glassfish.jersey.core\jersey-client\jars\jersey-client-2.22.2.jar;C:\Users\Miku.ivy2\cache\org.glassfish.jersey.containers\jersey-container-servlet-core\jars\jersey-container-servlet-core-2.22.2.jar;C:\Users\Miku.ivy2\cache\org.glassfish.jersey.containers\jersey-container-servlet\jars\jersey-container-servlet-2.22.2.jar;C:\Users\Miku.ivy2\cache\org.glassfish.jersey.bundles.repackaged\jersey-guava\bundles\jersey-guava-2.22.2.jar;C:\Users\Miku.ivy2\cache\org.glassfish.hk2.external\javax.inject\jars\javax.inject-2.4.0-b34.jar;C:\Users\Miku.ivy2\cache\org.glassfish.hk2.external\aopalliance-repackaged\jars\aopalliance-repackaged-2.4.0-b34.jar;C:\Users\Miku.ivy2\cache\org.glassfish.hk2\osgi-resource-locator\jars\osgi-resource-locator-1.0.1.jar;C:\Users\Miku.ivy2\cache\org.glassfish.hk2\hk2-utils\jars\hk2-utils-2.4.0-b34.jar;C:\Users\Miku.ivy2\cache\org.glassfish.hk2\hk2-locator\jars\hk2-locator-2.4.0-b34.jar;C:\Users\Miku.ivy2\cache\org.glassfish.hk2\hk2-api\jars\hk2-api-2.4.0-b34.jar;C:\Users\Miku.ivy2\cache\org.fusesource.leveldbjni\leveldbjni-all\bundles\leveldbjni-all-1.8.jar;C:\Users\Miku.ivy2\cache\org.codehaus.jettison\jettison\bundles\jettison-1.1.jar;C:\Users\Miku.ivy2\cache\org.codehaus.jackson\jackson-xc\jars\jackson-xc-1.9.13.jar;C:\Users\Miku.ivy2\cache\org.codehaus.jackson\jackson-mapper-asl\jars\jackson-mapper-asl-1.9.13.jar;C:\Users\Miku.ivy2\cache\org.codehaus.jackson\jackson-jaxrs\jars\jackson-jaxrs-1.9.13.jar;C:\Users\Miku.ivy2\cache\org.codehaus.jackson\jackson-core-asl\jars\jackson-core-asl-1.9.13.jar;C:\Users\Miku.ivy2\cache\org.bouncycastle\bcprov-jdk15on\jars\bcprov-jdk15on-1.52.jar;C:\Users\Miku.ivy2\cache\org.apache.zookeeper\zookeeper\jars\zookeeper-3.4.6.jar;C:\Users\Miku.ivy2\cache\org.apache.xbean\xbean-asm5-shaded\bundles\xbean-asm5-shaded-4.4.jar;C:\Users\Miku.ivy2\cache\org.apache.spark\spark-unsafe_2.11\jars\spark-unsafe_2.11-2.3.3.jar;C:\Users\Miku.ivy2\cache\org.apache.spark\spark-tags_2.11\jars\spark-tags_2.11-2.3.3.jar;C:\Users\Miku.ivy2\cache\org.apache.spark\spark-network-shuffle_2.11\jars\spark-network-shuffle_2.11-2.3.3.jar;C:\Users\Miku.ivy2\cache\org.apache.spark\spark-network-common_2.11\jars\spark-network-common_2.11-2.3.3.jar;C:\Users\Miku.ivy2\cache\org.apache.spark\spark-launcher_2.11\jars\spark-launcher_2.11-2.3.3.jar;C:\Users\Miku.ivy2\cache\org.apache.spark\spark-kvstore_2.11\jars\spark-kvstore_2.11-2.3.3.jar;C:\Users\Miku.ivy2\cache\org.apache.spark\spark-core_2.11\jars\spark-core_2.11-2.3.3.jar;C:\Users\Miku.ivy2\cache\org.apache.ivy\ivy\jars\ivy-2.4.0.jar;C:\Users\Miku.ivy2\cache\org.apache.httpcomponents\httpcore\jars\httpcore-4.4.1.jar;C:\Users\Miku.ivy2\cache\org.apache.httpcomponents\httpclient\jars\httpclient-4.5.jar;C:\Users\Miku.ivy2\cache\org.apache.hadoop\hadoop-yarn-server-common\jars\hadoop-yarn-server-common-2.6.5.jar;C:\Users\Miku.ivy2\cache\org.apache.hadoop\hadoop-yarn-common\jars\hadoop-yarn-common-2.6.5.jar;C:\Users\Miku.ivy2\cache\org.apache.hadoop\hadoop-yarn-client\jars\hadoop-yarn-client-2.6.5.jar;C:\Users\Miku.ivy2\cache\org.apache.hadoop\hadoop-yarn-api\jars\hadoop-yarn-api-2.6.5.jar;C:\Users\Miku.ivy2\cache\org.apache.hadoop\hadoop-mapreduce-client-shuffle\jars\hadoop-mapreduce-client-shuffle-2.6.5.jar;C:\Users\Miku.ivy2\cache\org.apache.hadoop\hadoop-mapreduce-client-jobclient\jars\hadoop-mapreduce-client-jobclient-2.6.5.jar;C:\Users\Miku.ivy2\cache\org.apache.hadoop\hadoop-mapreduce-client-core\jars\hadoop-mapreduce-client-core-2.6.5.jar;C:\Users\Miku.ivy2\cache\org.apache.hadoop\hadoop-mapreduce-client-common\jars\hadoop-mapreduce-client-common-2.6.5.jar;C:\Users\Miku.ivy2\cache\org.apache.hadoop\hadoop-mapreduce-client-app\jars\hadoop-mapreduce-client-app-2.6.5.jar;C:\Users\Miku.ivy2\cache\org.apache.hadoop\hadoop-hdfs\jars\hadoop-hdfs-2.6.5.jar;C:\Users\Miku.ivy2\cache\org.apache.hadoop\hadoop-common\jars\hadoop-common-2.6.5.jar;C:\Users\Miku.ivy2\cache\org.apache.hadoop\hadoop-client\jars\hadoop-client-2.6.5.jar;C:\Users\Miku.ivy2\cache\org.apache.hadoop\hadoop-auth\jars\hadoop-auth-2.6.5.jar;C:\Users\Miku.ivy2\cache\org.apache.hadoop\hadoop-annotations\jars\hadoop-annotations-2.6.5.jar;C:\Users\Miku.ivy2\cache\org.apache.directory.server\apacheds-kerberos-codec\bundles\apacheds-kerberos-codec-2.0.0-M15.jar;C:\Users\Miku.ivy2\cache\org.apache.directory.server\apacheds-i18n\bundles\apacheds-i18n-2.0.0-M15.jar;C:\Users\Miku.ivy2\cache\org.apache.directory.api\api-util\bundles\api-util-1.0.0-M20.jar;C:\Users\Miku.ivy2\cache\org.apache.directory.api\api-asn1-api\bundles\api-asn1-api-1.0.0-M20.jar;C:\Users\Miku.ivy2\cache\org.apache.curator\curator-recipes\bundles\curator-recipes-2.6.0.jar;C:\Users\Miku.ivy2\cache\org.apache.curator\curator-framework\bundles\curator-framework-2.6.0.jar;C:\Users\Miku.ivy2\cache\org.apache.curator\curator-client\bundles\curator-client-2.6.0.jar;C:\Users\Miku.ivy2\cache\org.apache.commons\commons-math3\jars\commons-math3-3.4.1.jar;C:\Users\Miku.ivy2\cache\org.apache.commons\commons-lang3\jars\commons-lang3-3.5.jar;C:\Users\Miku.ivy2\cache\org.apache.commons\commons-crypto\jars\commons-crypto-1.0.0.jar;C:\Users\Miku.ivy2\cache\org.apache.commons\commons-compress\jars\commons-compress-1.4.1.jar;C:\Users\Miku.ivy2\cache\org.apache.avro\avro-mapred\jars\avro-mapred-1.7.7-hadoop2.jar;C:\Users\Miku.ivy2\cache\org.apache.avro\avro-ipc\jars\avro-ipc-1.7.7-tests.jar;C:\Users\Miku.ivy2\cache\org.apache.avro\avro-ipc\jars\avro-ipc-1.7.7.jar;C:\Users\Miku.ivy2\cache\org.apache.avro\avro\jars\avro-1.7.7.jar;C:\Users\Miku.ivy2\cache\net.sf.py4j\py4j\jars\py4j-0.10.7.jar;C:\Users\Miku.ivy2\cache\net.razorvine\pyrolite\jars\pyrolite-4.13.jar;C:\Users\Miku.ivy2\cache\net.java.dev.jets3t\jets3t\jars\jets3t-0.9.4.jar;C:\Users\Miku.ivy2\cache\net.iharder\base64\jars\base64-2.3.8.jar;C:\Users\Miku.ivy2\cache\log4j\log4j\bundles\log4j-1.2.17.jar;C:\Users\Miku.ivy2\cache\jline\jline\jars\jline-0.9.94.jar;C:\Users\Miku.ivy2\cache\javax.xml.stream\stax-api\jars\stax-api-1.0-2.jar;C:\Users\Miku.ivy2\cache\javax.xml.bind\jaxb-api\jars\jaxb-api-2.2.2.jar;C:\Users\Miku.ivy2\cache\javax.ws.rs\javax.ws.rs-api\jars\javax.ws.rs-api-2.0.1.jar;C:\Users\Miku.ivy2\cache\javax.validation\validation-api\jars\validation-api-1.1.0.Final.jar;C:\Users\Miku.ivy2\cache\javax.servlet\javax.servlet-api\jars\javax.servlet-api-3.1.0.jar;C:\Users\Miku.ivy2\cache\javax.inject\javax.inject\jars\javax.inject-1.jar;C:\Users\Miku.ivy2\cache\javax.annotation\javax.annotation-api\jars\javax.annotation-api-1.2.jar;C:\Users\Miku.ivy2\cache\javax.activation\activation\jars\activation-1.1.1.jar;C:\Users\Miku.ivy2\cache\io.netty\netty-all\jars\netty-all-4.1.17.Final.jar;C:\Users\Miku.ivy2\cache\io.netty\netty\bundles\netty-3.9.9.Final.jar;C:\Users\Miku.ivy2\cache\io.dropwizard.metrics\metrics-jvm\bundles\metrics-jvm-3.1.5.jar;C:\Users\Miku.ivy2\cache\io.dropwizard.metrics\metrics-json\bundles\metrics-json-3.1.5.jar;C:\Users\Miku.ivy2\cache\io.dropwizard.metrics\metrics-graphite\bundles\metrics-graphite-3.1.5.jar;C:\Users\Miku.ivy2\cache\io.dropwizard.metrics\metrics-core\bundles\metrics-core-3.1.5.jar;C:\Users\Miku.ivy2\cache\commons-net\commons-net\jars\commons-net-2.2.jar;C:\Users\Miku.ivy2\cache\commons-lang\commons-lang\jars\commons-lang-2.6.jar;C:\Users\Miku.ivy2\cache\commons-io\commons-io\jars\commons-io-2.4.jar;C:\Users\Miku.ivy2\cache\commons-httpclient\commons-httpclient\jars\commons-httpclient-3.1.jar;C:\Users\Miku.ivy2\cache\commons-digester\commons-digester\jars\commons-digester-1.8.jar;C:\Users\Miku.ivy2\cache\commons-configuration\commons-configuration\jars\commons-configuration-1.6.jar;C:\Users\Miku.ivy2\cache\commons-collections\commons-collections\jars\commons-collections-3.2.2.jar;C:\Users\Miku.ivy2\cache\commons-codec\commons-codec\jars\commons-codec-1.13.jar;C:\Users\Miku.ivy2\cache\commons-cli\commons-cli\jars\commons-cli-1.2.jar;C:\Users\Miku.ivy2\cache\commons-beanutils\commons-beanutils-core\jars\commons-beanutils-core-1.8.0.jar;C:\Users\Miku.ivy2\cache\commons-beanutils\commons-beanutils\jars\commons-beanutils-1.7.0.jar;C:\Users\Miku.ivy2\cache\com.twitter\chill_2.11\jars\chill_2.11-0.8.4.jar;C:\Users\Miku.ivy2\cache\com.twitter\chill-java\jars\chill-java-0.8.4.jar;C:\Users\Miku.ivy2\cache\com.thoughtworks.paranamer\paranamer\bundles\paranamer-2.8.jar;C:\Users\Miku.ivy2\cache\com.ning\compress-lzf\bundles\compress-lzf-1.0.3.jar;C:\Users\Miku.ivy2\cache\com.jamesmurty.utils\java-xmlbuilder\jars\java-xmlbuilder-1.1.jar;C:\Users\Miku.ivy2\cache\com.google.protobuf\protobuf-java\bundles\protobuf-java-2.5.0.jar;C:\Users\Miku.ivy2\cache\com.google.inject\guice\jars\guice-3.0.jar;C:\Users\Miku.ivy2\cache\com.google.guava\guava\jars\guava-11.0.2.jar;C:\Users\Miku.ivy2\cache\com.google.code.gson\gson\jars\gson-2.2.4.jar;C:\Users\Miku.ivy2\cache\com.fasterxml.jackson.module\jackson-module-scala_2.11\bundles\jackson-module-scala_2.11-2.6.7.1.jar;C:\Users\Miku.ivy2\cache\com.fasterxml.jackson.module\jackson-module-paranamer\bundles\jackson-module-paranamer-2.7.9.jar;C:\Users\Miku.ivy2\cache\com.fasterxml.jackson.core\jackson-databind\bundles\jackson-databind-2.6.7.1.jar;C:\Users\Miku.ivy2\cache\com.fasterxml.jackson.core\jackson-annotations\bundles\jackson-annotations-2.6.7.jar;C:\Users\Miku.ivy2\cache\com.esotericsoftware\minlog\bundles\minlog-1.3.0.jar;C:\Users\Miku.ivy2\cache\com.esotericsoftware\kryo-shaded\bundles\kryo-shaded-3.0.3.jar;C:\Users\Miku.ivy2\cache\com.clearspring.analytics\stream\jars\stream-2.7.0.jar;C:\Users\Miku.ivy2\cache\com.carrotsearch\hppc\bundles\hppc-0.7.2.jar;C:\Users\Miku.ivy2\cache\com.fasterxml.jackson.core\jackson-core\bundles\jackson-core-2.7.9.jar;C:\Users\Miku.ivy2\cache\com.google.code.findbugs\jsr305\jars\jsr305-3.0.2.jar;C:\Users\Miku.ivy2\cache\com.univocity\univocity-parsers\jars\univocity-parsers-2.5.9.jar;C:\Users\Miku.ivy2\cache\com.vlkan\flatbuffers\jars\flatbuffers-1.2.0-3f79e055.jar;C:\Users\Miku.ivy2\cache\io.airlift\aircompressor\jars\aircompressor-0.8.jar;C:\Users\Miku.ivy2\cache\joda-time\joda-time\jars\joda-time-2.9.9.jar;C:\Users\Miku.ivy2\cache\org.antlr\antlr4-runtime\jars\antlr4-runtime-4.7.jar;C:\Users\Miku.ivy2\cache\org.apache.arrow\arrow-format\jars\arrow-format-0.8.0.jar;C:\Users\Miku.ivy2\cache\org.apache.arrow\arrow-memory\jars\arrow-memory-0.8.0.jar;C:\Users\Miku.ivy2\cache\org.apache.arrow\arrow-vector\jars\arrow-vector-0.8.0.jar;C:\Users\Miku.ivy2\cache\org.apache.orc\orc-core\jars\orc-core-1.4.4-nohive.jar;C:\Users\Miku.ivy2\cache\org.apache.orc\orc-mapreduce\jars\orc-mapreduce-1.4.4-nohive.jar;C:\Users\Miku.ivy2\cache\org.apache.parquet\parquet-column\jars\parquet-column-1.8.3.jar;C:\Users\Miku.ivy2\cache\org.apache.parquet\parquet-common\jars\parquet-common-1.8.3.jar;C:\Users\Miku.ivy2\cache\org.apache.parquet\parquet-encoding\jars\parquet-encoding-1.8.3.jar;C:\Users\Miku.ivy2\cache\org.apache.parquet\parquet-format\jars\parquet-format-2.3.1.jar;C:\Users\Miku.ivy2\cache\org.apache.parquet\parquet-hadoop\jars\parquet-hadoop-1.8.3.jar;C:\Users\Miku.ivy2\cache\org.apache.parquet\parquet-jackson\jars\parquet-jackson-1.8.3.jar;C:\Users\Miku.ivy2\cache\org.apache.spark\spark-catalyst_2.11\jars\spark-catalyst_2.11-2.3.3.jar;C:\Users\Miku.ivy2\cache\org.apache.spark\spark-sketch_2.11\jars\spark-sketch_2.11-2.3.3.jar;C:\Users\Miku.ivy2\cache\org.apache.spark\spark-sql_2.11\jars\spark-sql_2.11-2.3.3.jar;C:\Users\Miku.ivy2\cache\org.codehaus.janino\commons-compiler\jars\commons-compiler-3.0.8.jar;C:\Users\Miku.ivy2\cache\org.codehaus.janino\janino\jars\janino-3.0.8.jar;C:\Users\Miku.ivy2\cache\org.slf4j\slf4j-api\jars\slf4j-api-1.7.25.jar;C:\Users\Miku.ivy2\cache\mysql\mysql-connector-java\jars\mysql-connector-java-5.1.16.jar” JDBC.CommissionAmount
Exception in thread “main” com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
at com.mysql.jdbc.MysqlIO.(MysqlIO.java:344)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2333)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2370)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154)
at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:792)
at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at JDBC.CommissionAmount$.main(CommissionAmount.scala:42)
at JDBC.CommissionAmount.main(CommissionAmount.scala)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
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.(Socket.java:434)
at java.net.Socket.(Socket.java:244)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257)
at com.mysql.jdbc.MysqlIO.(MysqlIO.java:294)
… 16 more

Process finished with exit code 1

Please check in the code in the git and share it across so that our team can clone and troubleshoot the issue.

@harshini.karnati @annapurna

Below is the code that I have used:-
package JDBC

/**

  • Original Author : Itversity
  • class : Scala and Spark Live Training - 10 - Developing Scala applications
  • Dt : 19:08:2019
    */
    // Import Packages
    import java.sql.DriverManager

// Create case class EmployeeCommission to create objects for the query results
// In Web applications objects will be created and transferred between layers of it.

case class EmployeesCommission(first_name: String,
last_name:String,
salary: Double,
commission_pct: Double){
override def toString():String ={
s"first_name: " + first_name + "last_name: " + last_name +
“;” + “commission amount” + getCommissionAmount()
}
def getCommissionAmount():Any = {
if (commission_pct == 0){
“Not Elligible”
}else salary * commission_pct

}
}

object CommissionAmount {
def main(args: Array[String]): Unit = {
val driver = “com.mysql.jdbc.Driver”
val host = “nn01.itversity.com
val port = “3306”
val db = “hr”
val url = “jdbc:mysql://nn01.itversity.com:3306/hr”
//val url = “jdbc:mysql://” + host + “:” + port + “/” + db
val username = “hr_ro”
val password =“itversity”

Class.forName(driver)
val connection = DriverManager.getConnection(url,username,password)
val statement = connection.createStatement()
val resultset = statement.executeQuery("SELECT first_name,last_name" +
"salary,commission_pct FROM employees")

// Functional way of processing resultset
Iterator.
  continually(resultset.next(),resultset).
  takeWhile(_._1).
  map(r =>{
    EmployeesCommission(
      r._2.getString("first_name"),
      r._2.getString("last_name"),
      r._2.getDouble("salary"),
      r._2.getDouble("commission_pct")
       )
  }).
  toList.
  foreach(println)

}

}