Basic data handling with Java, MySQL and MongoDB
Libraries needed:
Given a database, this program is able to create a table pet
if pet
doesn't already exist.
mysql> describe pet;
Field | Type | Null | Key | Default | Extra |
---|---|---|---|---|---|
name | varchar(20) | YES | NULL | ||
owner | varchar(20) | YES | NULL | ||
species | varchar(20) | YES | NULL | ||
sex | char(1) | YES | NULL |
Other features of the program:
- Show all rows in the table.
- Insert new row.
- Delete a row given parameters (key, value).
DELETE FROM pet WHERE key=value
Compared to MySQL, MongoDB is more flexible regarding handling data.
Given a database test
, the program is able to:
- See all collections inside
test
. - Read all documents inside one collection.
- Create a new collection.
- Insert documents into a collection.
- Remove a document from a collection.
- Drop an entire collection.