TonyGW TonyGW - 3 years ago 153
Java Question

ORMLite JDBC error with connecting MySQL

I am following the ORMLite JDBC example at here 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 for further details.
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(
at com.j256.ormlite.jdbc.JdbcConnectionSource.initialize(
at com.j256.ormlite.jdbc.JdbcConnectionSource.<init>(
at com.j256.ormlite.jdbc.JdbcConnectionSource.<init>(
at main.CellPhoneDemo.main(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at com.intellij.rt.execution.application.AppMain.main(

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