0

I downloaded the MySQL JDBC driver to connect Scala to a MySQL database, but I cannot install it with java -jar mysql-connector-java-5.1.45-bin.jar. It says, no main manifest attribute, in mysql-connector-java-5.1.45-bin.jar

I cannot find any MANIFEST.MF file.

Any help would be appreciated.

EDIT: warnings after I run sbt run

[info] Loading project definition from /home/alessandro/Scala/tests/project
[info] Loading settings from build.sbt ...
[info] Set current project to MyProject (in build file:/home/alessandro/Scala/tests/)
[info] Running tests.ScalaJdbcConnectSelect 
Sun Feb 18 21:51:33 CET 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'pmanager.user' doesn't exist
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
    at com.mysql.jdbc.Util.getInstance(Util.java:408)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2480)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2438)
    at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1381)
    at tests.ScalaJdbcConnectSelect$.delayedEndpoint$tests$ScalaJdbcConnectSelect$1(ScalaJdbcConnectSelect.scala:16)
    at tests.ScalaJdbcConnectSelect$delayedInit$body.apply(ScalaJdbcConnectSelect.scala:5)
    at scala.Function0.apply$mcV$sp(Function0.scala:34)
    at scala.Function0.apply$mcV$sp$(Function0.scala:34)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App.$anonfun$main$1$adapted(App.scala:76)
    at scala.collection.immutable.List.foreach(List.scala:389)
    at scala.App.main(App.scala:76)
    at scala.App.main$(App.scala:74)
    at tests.ScalaJdbcConnectSelect$.main(ScalaJdbcConnectSelect.scala:5)
    at tests.ScalaJdbcConnectSelect.main(ScalaJdbcConnectSelect.scala)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at sbt.Run.invokeMain(Run.scala:93)
    at sbt.Run.run0(Run.scala:87)
    at sbt.Run.execute$1(Run.scala:65)
    at sbt.Run.$anonfun$run$4(Run.scala:77)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
    at sbt.util.InterfaceUtil$$anon$1.get(InterfaceUtil.scala:10)
    at sbt.TrapExit$App.run(TrapExit.scala:252)
    at java.base/java.lang.Thread.run(Thread.java:844)
[success] Total time: 3 s, completed Feb 18, 2018, 9:51:34 PM
A. N. Other
  • 409
  • 4
  • 14
  • The question was asked previously : [Can't execute jar- file: “no main manifest attribute”](https://stackoverflow.com/questions/9689793/cant-execute-jar-file-no-main-manifest-attribute?page=1&tab=votes#tab-top) – Mouna Ben Hmida Feb 17 '18 at 23:24
  • Where does it say you should execute the jar file to install it? You just have to add it to your *project* and its CLASSPATH. – user207421 Feb 17 '18 at 23:49

2 Answers2

1

UPDATE:

I found two options:

The first

In your build.sbt replace line

libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.24"

with this:

libraryDependencies ++= Seq(
"mysql" % "mysql-connector-java" % "5.1.16"
)

In command line:

sbt compile
sbt run

The second

Use this in command line:

set fullClasspath in Compile += Attributed.blank(file("path-to-your-connector-jar"))
sbt compile
sbt run

After that, the problem with the driver should disappear, but check the data to connect to the database.

BEFORE UPDATE:

In your project on Scala you also can use this:

package tests

import java.sql.{Connection,DriverManager}

object ScalaJdbcConnectSelect extends App {

  // connect to the database named "mysql" on port 8889 of localhost
  val url = "jdbc:mysql://localhost:8889/mysql"
  val driver = "com.mysql.jdbc.Driver"
  val username = "root"
  val password = "root"
  var connection:Connection = _
  try {
    Class.forName(driver)
    connection = DriverManager.getConnection(url, username, password)
    val statement = connection.createStatement
    val rs = statement.executeQuery("SELECT host, user FROM user")
    while (rs.next) {
      val host = rs.getString("host")
      val user = rs.getString("user")
      println("host = %s, user = %s".format(host,user))
    }
  } catch {
    case e: Exception => e.printStackTrace
  }
  connection.close
}

Link to source 1

Link to source 2

excelsiorious
  • 422
  • 9
  • 18
1

Please read this line:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'pmanager.user' doesn't exist

Check if there is such a table. If so, leave characters after the point (user).

excelsiorious
  • 422
  • 9
  • 18