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.

 DevX Skillbuilding from IBM developerWorks
 Avaya DevConnect Center
 Intel Go Parallel Portal
 Internet.com eBook Library
 Microsoft RIA Development Center
 Destination .NET
XML error: not well-formed (invalid token) at line 48
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%.

Apple Details iPhone/Mac Developer Event
RIM Ups Ante With Mobile Software Push
Novell Readies Silverlight Clone for Linux
Yahoo Pitches The 'Next Generation of Search'
Alfresco's Latest ECM: Prying Open a Sector?
SaaS Tool Offers Custom Database Development
Microsoft’s Automated Agent: Can We Talk?
Borland Finally Sells CodeGear
Red Hat Heads for the JON 2.0
Out with the Old, in with the New at JavaOne

Create Secure Java Applications Productively, Part 1: Use Rational Application Developer and Data Studio
.NET Building Blocks: Custom User Control Fundamentals
Secure Internet File-Sharing with PHP, MySQL, and JavaScript
Getting Started with TBB on Windows
Moving to VoIP: Should You Go It Alone?
Introduction to the WPF Command Framework
7.0, Microsoft's Lucky Version?
Will Hyper-V Make VMware This Decade's Netscape?
Eliminate Fragmentation Frustration with Netbiscuits
Taming Trees: Building Branching Structures

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



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Microsoft Article: 7.0, Microsoft's Lucky Version?
Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Windows Server 2008
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES