devloop icon
Metastores

Simple mapping tutorial

This tutorial shows you how to map a very simple class to a database table

First, we define the class that is going to be stored in the database:

	public class One {
		public	String	a = null;
		public	int	b = 0;
	}
download source

Then we use a simple command line program to create the schema and save an object:


	DBDataMapper dbm = new DBDataMapper();
	dbm.checkApplication(One.class);
	dbm.createSchema();
	One one = new One();
	IOHelper.insert(one);
	dbm.dropSchema();
download source

For reference, this is an indented extract of the output which is generated when using MySQL 5 as the backend database (the database instance is named 'testdb')

	QueryUtil(testdb[0])	executeUpdate([email protected],
		CREATE  TABLE One (b INT, a VARCHAR(255)), true)
	QueryUtil(testdb[0])	getPreparedStatement(
		INSERT INTO One(b,a) VALUES (?,?))
	QueryUtil(testdb[0])    executeUpdate([email protected],
		DROP TABLE One, true)

Related Links