|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV |
TOP THREE LINKS YOU MUST CLICK ON Advanced Java MM.MySQL and the MySQL Database System
MM.MySQL and the MySQL Database System
By: Mark Matthews
Feb. 1, 2000 12:00 AM
MySQL, and MM.MySQL, a JDBC driver for MySQL, are open-source tools that allow Java developers on Linux and other UNIX-like systems to develop full-featured applications. Both have similar histories - they started out as internal tools to fix a particular problem and grew to be much larger projects than the developers originally intended. I started developing MM.MySQL in May of 1998, to learn socket and JDBC development and to fix some problems with the original JDBC driver for MySQL, GWE. GWE development had ceased at that point and some features I required in a JDBC driver for MySQL weren't present. Since that time MM.MySQL has developed into a fairly capable Type IV (all Java) JDBC driver for MySQL. Depending on the JVM you're using, it supports the JDBC-1.2 or JDBC-2.0 API. It's been used with a majority of open-source Java tools like JBoss, Enhydra, and Tomcat, as well as Cocoon and Turbine. It's also supported by popular development environments such as Forté, JBuilder, IBM VisualAge for Java, and Macromedia UltraDev.
The MySQL Database System
Installing MySQL rpm -i MySQL-VERSION.i386.rpm MySQL-client-VERSION.i386.rpm This will install the MySQL server and client and also place entries in /etc/rc.d/ to start the MySQL server at boot up. If your system doesn't support installations via RPM, you'll need to download a binary distribution of MySQL. Their names are similar to mysql-VERSION-OS.tar.gz where VERSION is the version of the MySQL server and OS is the operating system the binary distribution has been compiled for. Once you've downloaded the binary distribution for your operating system, perform the following steps as root: shell> groupadd mysql After installing MySQL using RPMs or from a binary distribution, you need to create logins for users in MySQL. If you have Perl and DBI installed on your system as many standard Linux distributions do, you can use the "mysql_setpermissions" script to create users and passwords for your MySQL server. If you don't have Perl or DBI installed, read Chapter 6 in the manual that comes with the MySQL server since the topic of MySQL security could take up an entire magazine article!
Installing MM.MySQL If you're using a Java-2 JDK, the easiest installation method is to place the mysql-bin JAR file in the jre/lib/ext subdirectory that exists in your JDK's home directory. The JVM will then automatically load the driver when needed. If you're using a Java-1 JDK or don't have access to the jre/lib/ext subdirectory of your Java-2 JDK, add mysql-bin.jar to your CLASSPATH environment variable. For example, in UNIX with CSH you'd do the following: setenv CLASSPATH $CLASSPATH:/path/to/mysql-bin.jarwhere /path/to/mysql-bin.jar is the full path to where you've placed the mysql-bin JAR file. Often application servers don't refer to the CLASSPATH variable when determining where to load third-party libraries from. For example, with any J2EE-compliant application server you're deploying JSPs on, you can place the mysql-bin JAR file in the WEB-INF/lib sub-directory of your application. The application server will automatically load the driver from there. Other application servers require CLASSPATH to be set via their configuration files. Details for this configuration option can be found in the documentation for your application server.
Typical Usage Patterns
Where the hostname is the host that the database server is running on (defaults to localhost), the port is the TCP/IP port the server is listening on (only if it's listening on a nonstandard port), and dbname is the name of the database to connect to. The parameters (see Table 1) after the "?" allow you to pass more configuration information to the driver.
Using MySQL-Specific Functionality From either of these classes you can call the methods getLastInsertID() to get the value created for any AUTO_INCREMENT field and getLongUpdateCount() to get the larger update count that MySQL can produce as a long. Listing 1 shows how to do this. The JDBC API version 3, under development by JavaSoft, will have a portable way of retrieving AUTO_INCREMENT values; MM.MySQL will support that method when it becomes available.
Storing/Retrieving Serialized
Java Objects
As you've seen, MM.MySQL makes it extremely easy to store and retrieve Java objects. Because MySQL requires no special syntax to work with BLOBs, it's easy to manipulate data that contains them, which makes it easier to write queries that deal with BLOBs.
Conclusion As MM.MySQL is an open-source product, I'm always looking for suggestions for further development and assistance with development, so please contact me at mmatthew@thematthews.org for more information. LATEST JAVA STORIES & POSTS
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK SPONSORED BY INFRAGISTICS
BREAKING JAVA NEWS |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||