lalala
lalala

Reputation: 15

How to install MYSQL driver in H2 Console

I have an online MYSQL server and wish to edit query of it by using H2 Console. I have downloaded mysql-connector-java-8.0.21.jar and place it inside the /bin folder of H2 folder in my pc program files. But I still cannot connect to the server, it says Class "com.mysql.jdbc.Driver" not found [90086-200]. Does anyone knows how to fix it?

Upvotes: 1

Views: 2333

Answers (1)

The Impaler
The Impaler

Reputation: 48865

I never tried it before and I was surprised the H2 console web application can actually connect to other databases so easily.

You'll need to add MySQL's JDBC driver (MySQL 8.x in this example) in the command line when launching the H2 Console, as in:

$ java -cp <h2-driver>:<mysql-driver> org.h2.tools.Console

In my case this looked like:

$ java -cp jdbc-drivers/h2-1.4.197.jar:jdbc-drivers/mysql-connector-java-8.0.11.jar org.h2.tools.Console

With this command the H2 Console application shows up in the browser and you can connect to the MySQL 8.x database using the parameters similar to (adjust as needed):

  • Driver Class: com.mysql.cj.jdbc.Driver
  • JDBC URL: jdbc:mysql://localhost:3306/mydatabase
  • User Name: my_username
  • Password: my_password

Click "Connect" and it goes in. Then you can run any SQL statement, such as:

select version();

And it shows:

version()  
------------
8.0.3-rc-log

(1 row, 17 ms)

Awesome!

Upvotes: 3

Related Questions