Unable to load driver: com.mysql.jdbc.Driver

2019-08-12 23:58发布

问题:

I try to use Jasper to generate report in Laravel. It's work perfect if I didn't use database, if I add database to get data from mysql database he gives me an error "Unable to load driver: com.mysql.jdbc.Driver". I install JDBC Connector and Setup ODBC connection to local mysql server:

Also I setup CLASSPATH to MySQL connector:

Because laravel print me that have some error to generate pdf with database connection I change it to print output command and ran it in terminal and he gives me an error that "Unable to load driver: com.mysql.jdbc.Driver", see next picture:

If you have ANY idea I will be grateful!

回答1:

A lot of Java applications do not use the CLASSPATH environment variable, and it looks like jasperstarter is one of them.

Looking at http://jasperstarter.cenote.de/usage.html you need to use the command line option --jdbc-dir <directory with driver jar(s)>:

--jdbc-dir <dir> directory where jdbc driver jars are located. Defaults to ./jdbc

Alternatively, as you indicated in the comments, you can put the driver in the JasperStarter/jdbc folder, as that is the default location.