Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't test connection to mysql using Intellij

I'm on OSX Mavericks, running Intellij 12, trying to add a datasource already defined in XML, using the persistence facet.

I can find and select the source fine, but when I try to test the connection I get:

Connection to XXXXX failed: Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:190) at com.intellij.persistence.database.console.RemoteJdbcServer.main(RemoteJdbcServer.java:15)

Looks like it's just a classpath problem, but I'm having a surprisingly rough time figuring out what I have to do to get the mysql jar on the classpath.

Every question I've found deals with adding the jar to the classpath of your compiled or testing application, that's NOT what I'm looking for here. My application connects to mysql fine, it's the IntellijIDE that's having problems. Where do I need to add the path to this file?

like image 702
Lucas Lowry Avatar asked May 20 '14 22:05

Lucas Lowry


3 Answers

For Intellij 15 (maybe lower versions) this works:

Add the JDBC library using Intellij:

  1. Goto View -> Tool Windows -> Database.
  2. In the Database window, select a database and click the icon for data source properties (cmd+i).
  3. In the next window goto MySQL in the Drivers section. In the window left under driver files click download. That's it.
like image 103
frevib Avatar answered Sep 27 '22 16:09

frevib


In IntelliJ goto View -> Tool Windows -> Database

Inside Click + button -> DataSource -> MySql

as shown below

enter image description here

In below screen enter your mysql connection details and click Test Connection...

make sure you download mysql driver for connection

enter image description here

like image 24
Ali Avatar answered Sep 27 '22 18:09

Ali


Either of the following options should work

add jar to the global libraries of the project.

put jar in the lib directory of intellij.

put jar in the ext lib of the jre that intellij is running under.

like image 37
BevynQ Avatar answered Sep 27 '22 17:09

BevynQ