Thursday, June 6, 2013

Our Database: Dropping MySQL for MariaDB

This is part 2 of my Resteasy Tapestry with AngularJS tutorial. We will be fleshing out the database that we will be using for this tutorial/project.

I will be using MariaDB in this. I could use MySQL but ever since Oracle took it over, I've been slightly uncomfortable in using/recommending it. Besides, MariaDB is a drop-in replacement, so any code you wrote (or will write) for MySQL will be OK with a MariaDB database.

As not to be bogged down by database design details, we'll just have a 1 table database for Contacts.

As for our management tool, we will be using Netbeans. Yes, Netbeans. (I'll let that sink in.)

You can manage your MariaDB database in Netbeans just by registering it and running queries against it. And it does have a few GUI features like a 'Create-Table' wizard. To register your MariaDB database(I'm assuming that you have Netbeans and MariaDB installed already) do the following:

  1. Download the java-client driver  
  2. In Netbeans, go to the "Services" tab, right-click on it and select "New Connection"
  3. Pick new driver
  4. On the new window, locate the java-client driver you just downloaded
  5. Set the driver class to: org.mariadb.jdbc.Driver
  6. Pick a name for this new connection
You should be then able then to connect to your MariaDB instance. To test, try executing the command:

create database tangledb;

That should execute without a problem. As for creating a "Contacts" table, that should be fairly straight-forward. Just open up the new tangledb database and on the table folder, right-click and add new table.

As for the columns:
- id (integer, pk)
- firstname (varchar(50), nullable)
- lastname (varchar(50), nullable)
- nickname (varchar(50), not nullable)
- birthday (date)
- mobile (varchar(15), nullable)
- landline (varchar(15), nullable)
- e-mail (varchar(150), nullable)

Click OK and there you have your MariaDB database.