简体   繁体   English

Scala和MySQL JDBC驱动程序

[英]Scala and MySQL JDBC Driver

I'm currently working on a SBT-based Scala project and I need to use MySQL as database (through Slick 3.0.0 library). 我目前正在基于SBT的Scala项目中工作,我需要使用MySQL作为数据库(通过Slick 3.0.0库)。

The issue is that I can't connect to the database because of this exception: 问题是由于以下异常,我无法连接到数据库:

> service[ERROR] java.sql.SQLException: No suitable driver
service[ERROR]  at java.sql.DriverManager.getDriver(DriverManager.java:315)
service[ERROR]  at slick.jdbc.DriverBasedJdbcDataSource$class.registerDriver(JdbcDataSource.scala:60)
service[ERROR]  at slick.jdbc.DriverJdbcDataSource.registerDriver(JdbcDataSource.scala:72)
service[ERROR]  at slick.jdbc.DriverJdbcDataSource.<init>(JdbcDataSource.scala:78)
service[ERROR]  at slick.jdbc.JdbcBackend$DatabaseFactoryDef$class.forURL(JdbcBackend.scala:101)
service[ERROR]  at slick.jdbc.JdbcBackend$$anon$3.forURL(JdbcBackend.scala:33)

在此处输入图片说明

What I've done so far (see screenshot): 到目前为止,我已经完成了什么(请参见屏幕截图):

  • I made sure the MySQL server is running. 我确保MySQL服务器正在运行。

  • I've added mysql-connector-java dependency the build.sbt file. 我已经在build.sbt文件中添加了mysql-connector-java依赖 The jar gets downloaded correctly (see column on the left). 该jar文件已正确下载(请参阅左侧列)。

  • I've used this to get a connection to the database: 我用它来连接数据库:

     val db = Database.forURL( "jdbc:mysql/localhost:3306/service", "service", "service", driver="com.mysql.jdbc.Driver" ) 

Any idea on how to solve this? 关于如何解决这个问题的任何想法?

Thanks. 谢谢。

It should be jdbc:mysql://localhost:3306/service not jdbc:mysql/localhost:3306/service . 它应该是jdbc:mysql://localhost:3306/service而不是jdbc:mysql/localhost:3306/service You are missing a slash and colon after mysql. mysql之后,您缺少斜杠和冒号。

Tried on my own project. 在我自己的项目上尝试过。 The error with the wrong jdbc URL gives me same exception as yours. 错误的jdbc URL错误为我提供了与您相同的异常。 I guess this exception is misleading. 我想这个例外是误导的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM