How to connect to MySQL Database

352 views
Skip to first unread message

Raghs

unread,
Feb 17, 2009, 5:47:53 PM2/17/09
to H2 Database
Hi All,

I have been trying to connect to a MySQL Database which is already
existing. Though I have added the mysql connector jar file (with full
path) to an environment variable named H2DRIVERS as suggested in the
documentation, it keeps giving me an error "Database driver not
found". Am I missing something ?

Where are the entries with respect to the databases getting stored? I
just once tested by clicking on the 'Remove' button and it had taken
off the MySQL related entries. I had searched in "C:\Windows\Documents
and Settings\<userName>", the location where I had extracted the h2-
zip folder and ran the h2 executable jar. But no luck.

Moreover when I logged off, deleted and completely unzipped the
contents freshly, still I can see those entries in the Cache. Is it
getting stored in browser cache?

Thanks,
Raghavan alias Saravanan M.

Todd Stout

unread,
Feb 18, 2009, 8:12:15 AM2/18/09
to h2-da...@googlegroups.com
I don't understand what connecting to MySQL has to do with the H2 database.  If you want to connect to MySQL, use the MySQL JDBC driver. 

Raghavan.30May1981_GMail

unread,
Feb 18, 2009, 8:37:35 AM2/18/09
to h2-da...@googlegroups.com
That's fine. But my query was all about how to deal with the driver entries. The entries pertaining to the MySQL Driver seems to be vanishing once I clicked on 'Remove' button.

Further, even after setting the H2DRIVERS environment entry with the appropriate the MySQL JDBC Driver jar file, it still does NOT let me get connected and keeps me giving an error saying, "The driver was not found". Any rescue?

Cheers,
Raghavan alias Saravanan M.
http://groups.google.com/group/S_H_a_D_E

"Do not break the bridge that you might need to cross someday!!!" - Wisemen.

Raghavan.30May1981_GMail

unread,
Feb 18, 2009, 9:21:20 AM2/18/09
to h2-da...@googlegroups.com
I guess i missed out one part.. my question was based on the "H2 Console" wherein you can connect to other databases using the respective JDBC Driver.


Cheers,
Raghavan alias Saravanan M.
http://groups.google.com/group/S_H_a_D_E

"Do not break the bridge that you might need to cross someday!!!" - Wisemen.


Johann Schleier-Smith

unread,
Feb 18, 2009, 2:07:51 PM2/18/09
to h2-da...@googlegroups.com
Raghavan,

If it says "The driver was not found" then your problem is probably with the jdbc url, not the class path.

You can confirm that the MySQL client is properly loaded in the class path with the following commands:
CREATE ALIAS GET_PROPERTY FOR "java.lang.System.getProperty";
CALL GET_PROPERTY('java.class.path');

For example, on my system I have see:
h2-1.1.107.jar;C:\oracle\db\jdbc\lib\ojdbc5.jar;

Which reflects my environment variable setting:
H2DRIVERS=C:\oracle\db\jdbc\lib\ojdbc5.jar

You will have a MySql jar in place of the Oracle jar.

The jdbc url needs to be something like jdbc:mysql:... for the driver to be found.   E.g.,
CREATE LINKED TABLE LT ('com.mysql.jdbc.Driver','jdbc:mysql://localhost/test','username','password','tablename');

Raghavan.30May1981_GMail

unread,
Feb 20, 2009, 6:25:46 AM2/20/09
to h2-da...@googlegroups.com
Hi Johann,

 Thank you for the reply. I have executed those commands in the H2 console and all what it gives is the location of the jar file where h2 database has been picked up from. I have added the My SQL Connector Jar file into both CLASSPATH and H2DRIVERS environment variables. But when I try connecting to MySQL database with the proper Url, it does not let me get in. Any luck?


Cheers,
Raghavan alias Saravanan M.
http://groups.google.com/group/S_H_a_D_E

"Do not break the bridge that you might need to cross someday!!!" - Wisemen.


Johann Schleier-Smith

unread,
Feb 20, 2009, 6:07:44 PM2/20/09
to h2-da...@googlegroups.com
Raghavan,

Please send a copy of the complete statement that you are executing, as well as the full text of the error condition.  I'll let you know if it gives me any more ideas.

          - Johann

Thomas Mueller

unread,
Feb 24, 2009, 3:18:38 PM2/24/09
to h2-da...@googlegroups.com
Hi,

> it does not let me get in

What is the exact exception message and stack trace?

> Though I have added the mysql connector jar file (with full
> path) to an environment variable named H2DRIVERS as suggested in the
> documentation, it keeps giving me an error "Database driver not
> found". Am I missing something ?

How does your H2DRIVERS environment variable look like, and how do you
start the H2 Console? Basically, the MySQL JDBC driver needs to be in
the classpath. The H2DRIVERS environment variable is only used if you
start the H2 Console using the shell script / batch file included in
H2. If you start the H2 Console in some other way you need to make
sure the JDBC driver is in the classpath.

See also http://www.h2database.com/html/tutorial.html#tutorial_starting_h2_console
- Adding Database Drivers

>  Where are the entries with respect to the databases getting stored?

The password in the browser. The settings:
http://www.h2database.com/html/tutorial.html#console_settings

> just once tested by clicking on the 'Remove' button and it had taken
> off the MySQL related entries. I had searched in "C:\Windows\Documents
> and Settings\<userName>", the location where I had extracted the h2-
> zip folder and ran the h2 executable jar. But no luck.

You didn't find a file called .h2.server.properties ? If not could you
search for such a file? Maybe the user home directory is different in
your environment.

>  Moreover when I logged off, deleted and completely unzipped the
> contents freshly, still I can see those entries in the Cache. Is it
> getting stored in browser cache?

The password yes, but not the drop down list. Some browsers have
auto-complete but I don't think this is the problem.

Regards,
Thomas

oleg...@gmail.com

unread,
May 9, 2014, 6:58:49 AM5/9/14
to h2-da...@googlegroups.com
Hi. It's not question, but some information about.
I used Workbench/J (Build116) on Windows 8. And I had a problem whith
CREATE LINKED TABLE ...
It was error "class ... not found".
I find this messages and launch

CREATE ALIAS GET_PROPERTY FOR "java.lang.System.getProperty";
CALL GET_PROPERTY('java.class.path');
In results there was not my drivers pathes from H2DRIVERS (and other from system
enviroment CLASSPATH), only files from Workbench catalogue.
When I launch GET_PROPERTY from clonsole H2 - i saw, that pathes here, and i created
my table whithout any problem.
So, it's seems to me, that Workbench changes all pathess at it's own.
Buy.

среда, 25 февраля 2009 г., 7:18:38 UTC+11 пользователь Thomas Mueller написал:
Reply all
Reply to author
Forward
0 new messages