advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement


Reviews :

Mapping Java Objects to a Database with Castor-JDO:

Installation of MySQL

Castor supports all the well-known high-end databases like Oracle, DB2, MS SQL Server, but also Open Source databases like MySQL and Postgres. Here's the complete list of supported database systems. For all the examples in this article I've used MySQL, and for those of you who don't already have a database running on your computer I'll show you how to get one.   

You're always told that software is easy to install, right? This time it's true! MySQL is really simple to install and use. To use MySQL we need three software components: 

  • the MySQL server
  • a GUI client to administer the MySQL server
  • a Java JDBC driver 

You'll find them all on the MySQL download page: http://www.mysql.com/downloads/index.html.

The MySQL server: The production release is currently 3.23, but there is a "gamma" release called 4.0 which is recommended for new development, so let's pick that one. I used version 4.0.10 for this article. It's quite a bit to download, more than 20M for my Windows98 computer. On Windows you unzip the files, run the setup.exe, install in c:\mysql, and you're ready to go. 

There's a very comprehensive manual in the download, but why not start the server right away? Open a command prompt, go to the mysql\bin directory and type "mysqld", and the server is running. Verify this by typing "mysql" and you're in the server administrator. Now type "show databases;"--remember the semicolon! This will list the two databases--mysql and test--which come with the download. Enter "use test", and then create a new table called "media" in the "test" database:

create table media (id int primary key, type char(10) not null);

Enter "exit" to leave the administrator.   

The GUI client: Several clients exist. On the MySQL download page you'll find a link to "MySQL Control Center", which is a client that'll give you all the essential features you'd need to administer MySQL. Installation is straightforward. I used version 0.8.10 when preparing this article.

You should be able to see the new "media" table in the "test" database. 

The JDBC driver: Also on the download page you'll find "MySQL Connector/J", which is the official JDBC driver. Unzip the file you've downloaded and place the jar-file (there's only one) in your classpath. To see if your setup is correct try to compile and run this simple program that'll show the names of all tables in the "test" data base:

package hansen.playground;

import java.sql.*;

public class TestMySQL {
  public static void main(String[] args) {
    Connection connection = null;
    try {
      // Load the MySQL JDBC driver
      String driverName = "org.gjt.mm.mysql.Driver"; 
      Class.forName(driverName);
      
      // Create a connection to the "test" database
      String serverName = "localhost";
      String mydatabase = "test";
      String url = "jdbc:mysql://" + serverName +  "/" + mydatabase;
      String username = "root"; // default
      String password = ""; // default
      connection = DriverManager.getConnection(url, username, password);
      
      // Get the database metadata
      DatabaseMetaData dbmd = connection.getMetaData();
  
      // Specify the type of object; in this case we want tables
      String[] types = {"TABLE"};
      ResultSet resultSet = dbmd.getTables(null, null, "%", types);
  
      // Get the table names
      while (resultSet.next()) {
        // Get the table name
        String tableName = resultSet.getString(3);
        System.out.println("Table: " + tableName); 
      }
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
}

- Listing 1: Testprogram for MySQL -

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Microsoft Visual Studio 2010 Showcase
 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Windows 7: From Beta to Final Code in One Year
Google Shows Off Chrome OS, Releases Source
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?
Fedora 12 Takes Aim at Linux Networking
Top Supercomputer Nearly Doubles in Speed
Fedora 12 Linux Tackles Virtualization
Apple Gives iPhone Developers App Status Tracker
Novell Sets OpenSUSE 11.2 Free

Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Exploring HTML 5's Audio/Video Multimedia Support
Overriding Virtual Functions? Use C++0x Attributes to Avoid Bugs.
Understanding the Cloud Computing Security Vulnerabilities
Cisco and IBM Target a Greener World
Upgrade to Visual Studio 2010 with the Ultimate Offer

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs