Mit Java auf MySQL

oss studium
18-09-2005 | resmo

Letzthin im OOP-Unterricht wurde mir gezeigt (in 27 Schritten) wie man Java an eine DB mittels ODBC andockt. Tja, das kanns ja wohl nicht sein, dachte ich mir und da ich eh nur MySQL verwende, hab ich den MySQL Connector [1] für Java in Java gefunden, den man einfach in den CLASSPATH einbinden kann.

Hürde Eclipse Nur iregendwie klappte die Geschichte mit Eclipse nicht, da Eclipse ja einen CLASSPATH pro Projekt erstellt. Somit kann man mit right click auf sein Projekt --> Properties --> Java Build Path --> Add JARs das jar Archiv des Connector auswählen et voilà, aber...

Hürde MySQL MySQL wollte mich nicht reinlassen, ein Blick in die Knowledge Base [2] von dem Connector meinte dazu

MySQL Connector/J must use TCP/IP sockets to connect to MySQL, as Java does not support Unix Domain Sockets. Therefore, when MySQL Connector/J connects to MySQL, the security manager in MySQL server will use its grant tables to determine whether or not the connection should be allowed.

Somit muss man ein

GRANT ALL PRIVILEGES ON [dbname].* to '[user]'@'[hostname]' identified by '[password]';

machen damit MySQL die Türen öffnet.

[1] http://dev.mysql.com/doc/connector/j/en/index.html [2] http://dev.mysql.com/doc/connector/j/en/cj-faq.html