我在这里http://thecafetechno.com/tutorials/spring/spring-ormlite-example-integration-eclipse/关注ORMLite JDBC示例,以了解如何使用ORMLite在Java中连接到MySQL,但是当我在IntelliJ中运行程序时,我收到以下错误:
com.intellij.rt.execution.application.AppMain main.CellPhoneDemo
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:315)
at com.j256.ormlite.jdbc.JdbcConnectionSource.initialize(JdbcConnectionSource.java:135)
at com.j256.ormlite.jdbc.JdbcConnectionSource.<init>(JdbcConnectionSource.java:114)
at com.j256.ormlite.jdbc.JdbcConnectionSource.<init>(JdbcConnectionSource.java:56)
at main.CellPhoneDemo.main(CellPhoneDemo.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
我确信MySQL服务器正在我的Mac上运行,因为我使用了一个单独的工具“phpmyadmin”来访问数据库。我使用从Maven导入的java(版本5.1.29)的MySQL连接器。所以我很困惑可能出了什么问题?感谢
答案 0 :(得分:2)
我犯了一个愚蠢的错误。
String databaseUrl = "jdbc:mysql:/localhost:3306/my_db
应为String databaseUrl = "jdbc:mysql://localhost:3306/my_db
。