MySQL and Java - connectivity past, present, and future thoughts
Archive - Originally posted on "The Horse's Mouth" - 2010-07-09 06:33:13 - Graham EllisMySQL has migrated from MySQL AB (1995 to 2008) to Sun (2008 to 2010) to Oracle (from 27 Jan 2010)
wizard:java graham$ /usr/local/mysql/bin/mysql -uwellho -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.48 MySQL Community Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Java - originated by Sun and release in 1995, is now owned by Oracle too as part of its acquisition of Sun. When I visited the web service page at http://java.sun.com/webservices/ yesterday, I noted the following text at the base of the page:
Oracle is reviewing the Sun product roadmap and will provide guidance to customers in accordance with Oracle's standard product communication policies. Any resulting features and timing of release of such features as determined by Oracle's review of roadmaps, are at the sole discretion of Oracle. All product roadmap information, whether communicated by Sun Microsystems or by Oracle, does not represent a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. It is intended for information purposes only, and may not be incorporated into any contract.
© 2010, Oracle Corporation and/or its affiliates
What does this all mean?
On one hand, the brining together of MySQL and Java under a single ownership has enhanced the strength of the line between them. JDBC (the way that Java connects to all flavours of databases) ships as a set of manager classes only, and you need to download / install the actual drivers youself. In much earlier days, those were from a third party site and the class was loaded as follows into a Java application:
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
but the the support was taken up by the MySQL folks, and now that's a part of Oracle - I downloaded the drivers from dev.mysql.com yesterday, and now load them as follows into my Java appliaction:
Class.forName("com.mysql.jdbc.Driver").newInstance();
But on the other hand, I have no crystal ball and I cannot tell you where the Java and MySQL products will be taken; all I can do is to reproduce (for your own review) the text above and suggest that you follow through Oracle's communications if you wish, and that you factor in - as you feel appropriate - all of this information in any decision making with regard to future projects.
You may see my updated "Hello MySQL and Java World" example - which selects data from a database and displays it to the screen - [here]. I've added a whole load of annotation to that example, including test runs and an analysis of standard error messages (and possible solutions) such as:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
and
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The original example (but I have modernised the class load call) is [here] and for comparison we have a similar example that connects to an Oracle database [here].
[If you're looking to use MySQL from within Java from within a JSP (Java Server Page), there's a source code example of the class that we use on our Deploying Apache httpd and Tomcat training course [here] (we also cover programming Java Server Pages on some of our Java Courses).]