TonyGW TonyGW - 3 years ago 153
Java Question

ORMLite JDBC error with connecting MySQL

I am following the ORMLite JDBC example at here http://thecafetechno.com/tutorials/spring/spring-ormlite-example-integration-eclipse/ to learn how to connect to MySQL in Java by using ORMLite, but when I run the program in IntelliJ, I got the following error:

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)


I am sure MySQL server is running on my Mac, because I used a separate tool "phpmyadmin" to access the database. I use the MySQL connector for java (version 5.1.29) imported by from Maven. So I am confused what might have gone wrong? Thanks

Answer Source

I made a silly mistake.

String databaseUrl = "jdbc:mysql:/localhost:3306/my_db should be String databaseUrl = "jdbc:mysql://localhost:3306/my_db.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download