我无法在Ubuntu 16.04上安装MySQL JDBC驱动程序

时间:2018-02-17 23:08:28

标签: jdbc ubuntu-16.04 mysql-connector manifest.mf

我下载了MySQL JDBC驱动程序以将Scala连接到MySQL数据库,但我无法使用java -jar mysql-connector-java-5.1.45-bin.jar安装它。它说,没有主要的清单属性,在mysql-connector-java-5.1.45-bin.jar

我找不到任何MANIFEST.MF文件。

任何帮助都将不胜感激。

编辑:运行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

2 个答案:

答案 0 :(得分:1)

<强>更新

我找到了两个选项:

第一个

build.sbt替换行

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

用这个:

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

在命令行中:

sbt compile
sbt run

第二个

在命令行中使用它:

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

之后,驱动程序的问题应该消失,但检查数据以连接到数据库。

更新前:

在Scala上的项目中,你也可以使用它:

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

答案 1 :(得分:1)

请阅读以下这一行:

   func changeViewSize(from: CGFloat, to: CGFloat, indexPath: IndexPath) {
    UIView.transition(with: myCollection, duration: 0.5, options: .beginFromCurrentState, animations: {() -> Void in
        let cell = self.myCollection.cellForItem(at: indexPath)!
        let cellCenter = CGPoint(x: cell.center.x, y: cell.center.y + 50)
        if cell.bounds.height == from {
            let sizee = CGRect(x: cell.center.x, y: cell.center.y, width: cell.frame.width, height: to)
            self.myCollection.cellForItem(at: indexPath)?.frame = sizee
            self.myCollection.cellForItem(at: indexPath)?.center = cellCenter
            for x in self.indexPathss {
                if x.row > indexPath.row {
                    print("this is cells")
                    print(self.myCollection.visibleCells)
                    let cell = self.myCollection.cellForItem(at: x)!
                    cell.center.y += 100
                }
            }
        }
    }, completion: {(_ finished: Bool) -> Void in
        print("finished animating of cell!!!")
    })
}

检查是否有这样的表格。如果是,请在点(com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'pmanager.user' doesn't exist )之后留下字符。