我无法在 Ubuntu 16.04 上安装 MySQL JDBC 驱动程序
I cannot install MySQL JDBC driver on Ubuntu 16.04
我下载了 MySQL JDBC 驱动程序以将 Scala 连接到 MySQL 数据库,但我无法使用 java -jar mysql-connector-java-5.1.45-bin.jar
安装它。它说,no main manifest attribute, in 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(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$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(Run.scala:65)
at sbt.Run.$anonfun$run(Run.scala:77)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
at sbt.util.InterfaceUtil$$anon.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
更新:
我找到了两个选项:
第一个
在你的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
}
请阅读这一行:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'pmanager.user' doesn't exist
检查是否存在table。如果是这样,请在点后留下字符 (user
).
我下载了 MySQL JDBC 驱动程序以将 Scala 连接到 MySQL 数据库,但我无法使用 java -jar mysql-connector-java-5.1.45-bin.jar
安装它。它说,no main manifest attribute, in 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(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$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(Run.scala:65)
at sbt.Run.$anonfun$run(Run.scala:77)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
at sbt.util.InterfaceUtil$$anon.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
更新:
我找到了两个选项:
第一个
在你的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
}
请阅读这一行:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'pmanager.user' doesn't exist
检查是否存在table。如果是这样,请在点后留下字符 (user
).