• (2 Pages)
  • +
  • 1
  • 2

Inserting Java objects into an HSQLdb database Rate Topic: ***** 3 Votes

#1 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Posted 01 July 2009 - 05:49 PM

Many the question has been asked in the forum:
How to put a Java object into a DataBase ?

How does serialization been performed ? BLOB and CLOB ?

Here an example using HSQLdb. Why HSQLdb ? Because first, it is the database I use :-)
But also because HSQLdb, even if not as well known as MySQL is 100% Java based.
You can store an remove Java objects from HSQLdb as long as they implement Serializable.

If your BD will always be accessed by Java there is no reason not to use HSQLdb.
It can be downloaded from here

http://www.hsqldb.org/
the only thing you will download is a single .jar file:
hsqldb.jar

HSQLdb can be used in 2 modes:
- in StandAlone mode
- regular ClientServer mode

in StandAlone mode, the HSQLdb driver is imbedded in your application. So you cannot share the DataBase
with another application but if your application is stand alone and you are the only
one using the database that is the best way to go.

Both mode will be explained.
I tried to make a simple example. A database with 3 tables each of them will hold
instance of a simple Java object.

The first table: FirstNameTable which has 3 columns:
- The object FirstName
- The table unique Id
- The FirstName as a String (for uniqueness)

The second table: LastNameTable which has 3 columns:
- The object LastName
- The table unique Id
- The FirstName as a String (for uniqueness)

The third table: FullNameTable which has 4 columns:
- The object FullName
- The table unique Id
- A foreign key on a row of FirtNameTable
- A foreign key on a row of LastNameTable

The tables unique Id are very usefull and each object in the DB will contain its unique Id.
To share a lot of method for SQL access many of them will use GetSetId interface.
This inetrafce should be implement by all objects going in the DB

/*
 ** All the objects stored in the DB must implements these 2 methods
 ** that allows to store/retreive the DB unique Id within a table
 */
public interface GetSetId {

	// to get the BD unique Id
	public int getId();
	// to set it in an object after reading the object from the DB
	public void setId(int id);
}



OK now. The FirstName and LastName objects are just a clone of each of other.
So I made a class GenericName from where FirstName and LastName derive.

/*
 * * This class will be overload by both FirstName and LastName
 * * It must implement Serializable
 */
public class GenericName implements Serializable, GetSetId {

	// use for serialization
	private static final long serialVersionUID = 200906292210L;
	
	// the actual only element stored in the DB
	private String name;
	// the unique Id whitin the table in the DB that will be generate by the DB
	// this element is not stored in the DB
	transient private int id;
	
	// constructor that receives the Name as parameter
	GenericName(String name) {
		setName(name);
	}
	
	// getters and setters
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	String getName() {
		return name;
	}
	void setName(String name) {
		this.name = name;
	}
	// displayed name	
	public String toString() {
		return "[" + id + "]" + " " + name;
	}

}



Note that the int id variable is transient. It will not be stored in the serialized
object that will be store in the DataBase. One of the reason for that is that it is the
database that will generate that number when you will store an elemnt in the DB and
you cannot know it before storing the object in the database.

All serialized class must have a private static final long serialVersionUID.

private static final long serialVersionUID = 200906292210L;

I usually put the date where I wrote the class the first time in format YYYMMDDHHMM
this garanties me uniqueness as I do not usually write more than one class per minute :-)

So now how does my FirstName and LastName class look like:

import java.io.Serializable;

/**
 * This class define is the object FirstName that will be stored in the DB
 * An object that wants to be stored in a DB needs to implement Serializable
 */
public class FirstName extends GenericName implements Serializable {

	// This a unique number that will be used during serialization
	private static final long serialVersionUID = 200906271625L;

	// Constructor that calls the father GenericName
	FirstName(String name) {
		super(name);
	}




import java.io.Serializable;

/**
 * This class define is the object LastName that will be stored in the DB
 * An object that wants to be stored in a DB needs to implement Serializable
 */
public class LastName extends GenericName implements Serializable {

	// This a unique number that will be used during serialization
	private static final long serialVersionUID = 200906271600L;

	// Constructor that calls the father GenericName
	LastName(String name) {
		super(name);
	}



And the FullName class which has a FirstName a LastName and an age as integer
import java.io.Serializable;

/**
 * This class define is the object FullName that will be stored in the DB
 * An object that wants to be stored in a DB needs to implement Serializable
 */
public class FullName implements Serializable, GetSetId {

	// This a unuique number that will be used during serialization
	private static final long serialVersionUID = 200906271650L;

	// the Id of both FirstName and LastName
	private int lastNameId, firstNameId;
	// the age of the person
	private int age;
	
	// all the other variables are transient, they are not stored in the database
	// my own unique id in the DB
	private transient int id;
	
	// The FirstName and LastName objects (these are transient because not stored in the DB)
	private transient LastName lastName;
	private transient FirstName firstName;
	
	// Constructor that calls the father
	FullName(FirstName firstName, LastName lastName, int age) {
		this.lastName = lastName;
		this.firstName = firstName;
		lastNameId = lastName.getId();
		firstNameId = firstName.getId();
		this.age = age;
	}

	public String toString() {
		return lastName.getName() + ", " + firstName.getName() + "  " + age + " years old";
	}

	public int getId() {
		return id;
	}
	// this one is called when read from the DB
	// we have to fill our transient fields
	public void setId(int id) {
		this.id = id;
		firstName = FirstNameTable.getInstance().getById(firstNameId);
		lastName = LastNameTable.getInstance().getById(lastNameId);
	}

	public final int getLastNameId() {
		return lastNameId;
	}

	public final void setLastNameId(int lastNameId) {
		this.lastNameId = lastNameId;
	}

	public final int getFirstNameId() {
		return firstNameId;
	}

	public final void setFirstNameId(int firstNameId) {
		this.firstNameId = firstNameId;
	}
	
	public int getAge() {
		return age;
	}



Don't worry for now on how the firstName and lastName are set in method setId()
we'll see that later. These code of these 3 classes is not all showed yet
but don't worry complete code will be showed later.

OK now we have 3 classes to handle the 3 tables in the DataBase.
We have FirstNameTable, LastNameTable and FullNameTable.
Many methods are common to these 3 classes and are defined in DbTable.
The 3 classes derives from DbTable

package ca.pblinc.hsqldb;

import java.sql.*;
import java.util.ArrayList;

/*
 * All tables classes must extends this class. It conatins
 * - the DB Connection object
 * - the common PreparedStatement
 * - common methods
 * Note: we assume DB Username is "sa" and password is ""
 */
public class DbTable {
	// path for standalone mode
	private static final String dbPathStandAlone = "jdbc:hsqldb:file:";
	// path for server mode
	private static final String dbPathWithServer = "jdbc:hsqldb:hsql://";

	// the unique Connection object used and shared by all tables
	static Connection con;
	// a unique instance of this
	static DbTable instance;
	// the common PreparedStatement
	PreparedStatement prstInsert, prstUpdate, prstDelete, prstGetById, prstSelectAll;
	// to get the last Id of an element inserted in the Bd
	private static PreparedStatement prstGetLastId;

	// there are 2 constructor one for Standlone mode and one for server mode

	// In process mode receives the name of the DB filename
	DbTable(String dbName) {
		System.out.println("Constructor of DbTable in StandAlone mode");
		// load HSQLdb driver
		loadDriver();
		// try to connect in standalone mode
		try {
			con = DriverManager.getConnection(dbPathStandAlone + dbName, "sa", "");
			System.out.println("Correctly connected in StandAlone mode.");
		}
		catch (SQLException e) {
			int code = e.getErrorCode();
			System.out.println("getConnection failed: " + code + " " + e);
			throw new IllegalStateException("Cannot connect to DB in StandAlone mode.");
		}
		// create tables object
		createTables();
	}

	// Server mode receives pseudo name of the bd offerered by the server and server IP address
	DbTable(String dbName, String host) {
		System.out.println("Consructor of DBTable in Server Mode");
		//bdName load HSQLdb driver
		loadDriver();
		// try to connect to the server
		try {
			con = DriverManager.getConnection(dbPathWithServer + host + "/" + dbName, "sa", "");
			System.out.println("Correctly connected in to the server.");
		}
		catch (SQLException e) {
			int code = e.getErrorCode();
			System.out.println("getConnection failed: " + code + " " + e);
			throw new IllegalStateException("Cannot connect to DB server.");
		}
		// create tables object
		createTables();
	}

	// an empty constructor for the ones that extend me
	DbTable() {		
	}

	// use to load the HSQLdb driver use by both connection type
	private void loadDriver() {
		instance = this;
		try {
			Class.forName("org.hsqldb.jdbcDriver"); //.newInstance();
			System.out.println("HSQLdb driver correctly loaded.");
		}
		catch (Exception e) {
			System.out.println("Problem loading JDBC driver: " + e);
			throw new IllegalStateException("HSQLDB driver couldn't be loadded.");
		}
	}

	// common part that are executed both in StandAlone mode and in Server mode
	// it creates an instance of all xxxxTable so object can access them
	void createTables() {
		// build the PrepareStement to get the Id of the last element inserted in the Db
		// only one for all tables so it is a static variable
		try {
			prstGetLastId = con.prepareStatement("call identity()");
		} 
		catch (SQLException e) {
			System.out.println("Problem creating prstGetId PreparedStatement.");
			throw new IllegalStateException("Problem creating prstGetId PreparedStatement.");
		}
		// creates all other tables object
		new FirstNameTable();
		new LastNameTable();
		new FullNameTable();
	}

	/** Share method to get a resultSet from an SQL string */
	protected ResultSet queryExecute(String sqlString) {
		try {
			PreparedStatement stmt = con.prepareStatement(sqlString);
			return queryExecute(stmt);
		}
		catch (SQLException e) {
			int code = e.getErrorCode();
			System.out.println("queryExecute building prepStatement " + sqlString + " returns " + code + " "+ e);
			return null;
		}
	}
	/** General method to execute a query using a PreparedStatement */
	protected ResultSet queryExecute(PreparedStatement stmt) {
		System.out.println("DbTable.queryExecute(" + stmt + ")");
		try {
			ResultSet result = stmt.executeQuery();
			return result;	   
		}
		catch (SQLException e) {
			System.out.println("queryExecute: " + stmt + " returns " + e);
			return null;		
		}				  
	}

	/** General method to do a statement.execute from a String. Returns the number of rows affected  */
	int statementExecute(String sql)
	{
		int nb = -1;
		try {
			PreparedStatement stmt = con.prepareStatement(sql);		// on prepare le statement
			nb = statementExecute(stmt);
		}
		catch (SQLException e) {
			System.out.println("StatementExecute building prepStatement for " + sql + " returns: " + e);
		}
		System.out.println("statementExecute(" + sql + ") returns " + nb);
		return nb;
	}

	/** General method to do a statementExecute from a PreparedStatement. Returns the number of rows affected */
	int statementExecute(PreparedStatement stmt)
	{
		int nb = -1;
		try {
			nb = stmt.executeUpdate();						// la commande passee en parametre
		}
		catch (SQLException e) {
			int code = e.getErrorCode();
			System.out.println("statementExecute: " + stmt);
			System.out.println("status: " + code + ">> "+ e);
		}
		return nb;
	}

	/*
	 * returns the row count from a table whose name is passed as parameter
	 * returns -1 if the table does not exist
	 */
	int getCount(String tableName) {
		int nb = -1;
		String sql = "SELECT COUNT(*) FROM " + tableName + ";";

		// call our queryExcute method
		ResultSet rs = queryExecute(sql);
		// if ResultSet is nulll returns -1
		if(rs == null) {
			System.out.println("GetCount() on " + tableName + " returns " + nb);
			return nb;
		}
		// fetch rows count
		try {
			rs.next();
			nb = rs.getInt(1);
			rs.close();
		}
		catch (SQLException e) {
			throw new IllegalStateException("DbTable.getCount() rs.getNext() or rs.getInt Exception: " + e);		
		}

		System.out.println("GetCount() on " + tableName + " returns " + nb);
		return nb;
	}

	/** Returns the Id of the last element inserted into the DB */
	int getIdentity() {
		ResultSet rs = queryExecute(prstGetLastId);
		try {
			rs.next();
			int id = rs.getInt(1);
			rs.close();
			return id;
		}
		catch (SQLException e) {
			throw new IllegalStateException("Something wrong with getIdentity().");
		}
	}

	// returns an ArrayList of all the elements in a table. All our objects implements GetSetId.
	protected ArrayList<GetSetId> sqlSelectAll() {
		ArrayList<GetSetId> al = new ArrayList<GetSetId>();
		ResultSet rs = queryExecute(prstSelectAll);
		try {
			// scan the ResultSet to extract all FirstName
			while(rs.next()) {
				GetSetId obj = (GetSetId) rs.getObject(1);	// get next object in column 1
				int id = rs.getInt(2);						// get its id in column 2
				obj.setId(id);								// set the object Id into the transient instance variable
				al.add(obj);								// added to the array list
			}
			// free the resources of the working set
			rs.close();
		}
		catch(SQLException e) {
			System.out.println("DbTable.selectAll() exception: " + e + " for " + prstSelectAll);
		}

		return al;
	}

	// delete an object from the database
	boolean sqlDelete(GetSetId obj) {
		try {
			prstDelete.setInt(1, obj.getId());
			return statementExecute(prstDelete) > 0;
		}
		catch(SQLException e) {
			System.out.println("DbTable.deleteById exception: " + e);
		}
		// obviously didn't work
		return false;
	}
	
	/*
	 * returns a row by its Id. The classes that call this method will cast the GetSetId object to
	 * the object they served (FirstName, LastName or FullName)
	 */
	GetSetId sqlGetById(int id) {
		try {
			prstGetById.setInt(1, id);
			ResultSet rs = queryExecute(prstGetById);
			if(rs == null)
				return null;
			if(!rs.next())
				return null;
			GetSetId obj = (GetSetId) rs.getObject(1);	// get next object in column 1
			obj.setId(id);
			return obj;
		}
		catch(SQLException e) {
			System.out.println("sqlGetById exception for Id: " + id + " Error: " + e);
		}
		return null;
	}
	// returns the Connection object to the DB
	static DbTable getInstance() {
		return instance;
	}
}


Note that this class contains a lot of System.out.println() that can be removed when
you'll understand how all the stuff works.

OK let see now how the 3 other classes extend that DbTable

Now that you know that objects FirstNameTable, LastNameTable and FullNameTable we can
complete the code of their respective FirstName, LastName and FullName

import java.io.Serializable;

/**
 * This class define is the object FirstName that will be stored in the DB
 * An object that wants to be stored in a DB needs to implement Serializable
 */
public class FirstName extends GenericName implements Serializable {

	// This a unique number that will be used during serialization
	private static final long serialVersionUID = 200906271625L;

	// Constructor that calls the father GenericName
	FirstName(String name) {
		super(name);
	}
	
	// insert that object into the DB
	boolean sqlInsert() {
		// get the singleton of my table
		FirstNameTable table = FirstNameTable.getInstance();
		// calls the method to insert a FirstName
		return table.sqlInsert(this);
	}
	
	// delete this object from the db
	boolean sqlDelete() {
		// get the singleton of my table
		FirstNameTable table = FirstNameTable.getInstance();
		// calls the method to insert a FirstName
		return table.sqlDelete(this);
	}
	
	// update this object
	boolean sqlUpdate() {
		// get the singleton of my table
		FirstNameTable table = FirstNameTable.getInstance();
		// calls the method to insert a FirstName
		return table.sqlUpdate(this);		
	}
}


import java.io.Serializable;

/**
 * This class define is the object LastName that will be stored in the DB
 * An object that wants to be stored in a DB needs to implement Serializable
 */
public class LastName extends GenericName implements Serializable {

	// This a unique number that will be used during serialization
	private static final long serialVersionUID = 200906271600L;

	// Constructor that calls the father GenericName
	LastName(String name) {
		super(name);
	}

	// insert that object into the DB
	boolean sqlInsert() {
		// get the singleton of my table
		LastNameTable table = LastNameTable.getInstance();
		// calls the method to insert a FirstName
		return table.sqlInsert(this);
	}
	
	// delete this object from the db
	boolean sqlDelete() {
		// get the singleton of my table
		LastNameTable table = LastNameTable.getInstance();
		// calls the method to insert a FirstName
		return table.sqlDelete(this);
	}
	
	// update this object
	boolean sqlUpdate() {
		// get the singleton of my table
		LastNameTable table = LastNameTable.getInstance();
		// calls the method to insert a FirstName
		return table.sqlUpdate(this);		
	}
}


import java.io.Serializable;

/**
 * This class define is the object FullName that will be stored in the DB
 * An object that wants to be stored in a DB needs to implement Serializable
 */
public class FullName implements Serializable, GetSetId {

	// This a unuique number that will be used during serialization
	private static final long serialVersionUID = 200906271650L;

	// the Id of both FirstName and LastName
	private int lastNameId, firstNameId;
	// the age of the person
	private int age;
	
	// all the other variables are transient, they are not stored in the database
	// my own unique id in the DB
	private transient int id;
	
	// The FirstName and LastName objects (these are transient because not stored in the DB)
	private transient LastName lastName;
	private transient FirstName firstName;
	
	// Constructor that calls the father
	FullName(FirstName firstName, LastName lastName, int age) {
		this.lastName = lastName;
		this.firstName = firstName;
		lastNameId = lastName.getId();
		firstNameId = firstName.getId();
		this.age = age;
	}

	public String toString() {
		return lastName.getName() + ", " + firstName.getName() + "  " + age + " years old";
	}

	public int getId() {
		return id;
	}
	// this one is called when read from the DB
	// we have to fill our transient fields
	public void setId(int id) {
		this.id = id;
		firstName = FirstNameTable.getInstance().getById(firstNameId);
		lastName = LastNameTable.getInstance().getById(lastNameId);
	}

	public final int getLastNameId() {
		return lastNameId;
	}

	public final void setLastNameId(int lastNameId) {
		this.lastNameId = lastNameId;
	}

	public final int getFirstNameId() {
		return firstNameId;
	}

	public final void setFirstNameId(int firstNameId) {
		this.firstNameId = firstNameId;
	}
	
	public int getAge() {
		return age;
	}
	// insert that object into the DB
	boolean sqlInsert() {
		// get the singleton of my table
		FullNameTable table = FullNameTable.getInstance();
		// calls the method to insert a FirstName
		return table.sqlInsert(this);
	}

	// delete this object from the db
	boolean sqlDelete() {
		// get the singleton of my table
		FullNameTable table = FullNameTable.getInstance();
		// calls the method to insert a FirstName
		return table.sqlDelete(this);
	}
	
	// update this object
	boolean sqlUpdate() {
		// get the singleton of my table
		FullNameTable table = FullNameTable.getInstance();
		// calls the method to insert a FirstName
		return table.sqlUpdate(this);		
	}

}



OK now let us look at the 3 classes that extend DbTable
When each of these xxxTable object constructor is called, if the Table does not exist
in the database it is created.
Note: for testing purpose: if the table is created there is code to add some
predefined entries in the database.
More than that, the FirstNameTable has code to test the Update and Delete transaction.
The FullNameTable, when first created, generates randomly choosen FullName from FirstName
and LastName with also a randomly selected age.
If the table already exist, a list of all the elements in the table is showed.

import java.sql.*;
import java.util.*;

// handles the FirstNameTable
public class FirstNameTable extends DbTable{

	// this table is a Singleton
	private static FirstNameTable instance;
	// predefined FirstName to be used if DB is empty
	private static final String[] fName = {"paul", "benoit", "john", "neo", "cabbage", "honey", "mike"};
	// Table name and is create statement
	private static final String tableName = "FirstNameTable";
	// by default HSQLdb creates in memory table we need the keyword "Cached Table" to make it on disk
	private static final String createTable = 
		"Create Cached Table " + tableName + " (" +
		"Obj OBJECT, " +							// the Object implementing GetSetId()
		"Id INTEGER IDENTITY PRIMARY KEY, " + 		// unique Id within that table
		"Name VARCHAR(1024) NOT NULL, " +			// the name unique (not case sensitive) within the table
		"UNIQUE (Id), " +
		"UNIQUE (Name)" +
		");";
	
	/*
	 * This class handles the SQL requests to the FirstNameTable
	 */
	FirstNameTable() {
		instance = this;
		// a flag to inform us if the table existed or not
		// if it didn't exist we will populate it
		boolean tableExisted = true;
		// we check if the table exist if not we create it
		if(getCount() == -1) {
			// flag table creation
			tableExisted = false;
			statementExecute(createTable);			// lets create it
			// I hate tableId starting at 0 (personal preference so I set the Id to start at 1)
	 		statementExecute("ALTER TABLE " + tableName + " ALTER COLUMN Id RESTART WITH 1;");					
	 	}
		
		// we create our PreparedStatements
		try {
			prstInsert = con.prepareStatement("INSERT INTO " + tableName + " (Obj, Id, Name) VALUES (?, ?, ?)");
			prstUpdate = con.prepareStatement("UPDATE " + tableName + " SET Name = ?, Obj = ? WHERE Id = ?;");
			prstDelete = con.prepareStatement("DELETE FROM " + tableName + " WHERE Id = ?;");
			prstGetById = con.prepareStatement("SELECT Obj FROM " + tableName + " WHERE Id = ?;");
			prstSelectAll = con.prepareStatement("SELECT Obj, Id FROM " + tableName + " ORDER BY Name;");
		}
		catch(SQLException e) {
			System.out.println("Problem creating PreparedStatement for " + tableName + ".");
			throw new IllegalStateException("Problem creating PreparedStatement for " + tableName + ".");
		}
		
		// now if the table didn't exist we fill it with our predefined elements
		if(!tableExisted) {
			// loopt throught our predifed name to initialize the table
			for(int i = 0; i < fName.length; i++) {
				// create FirtName object
				FirstName fn = new FirstName(fName[i]);
				// insert it into DB
				fn.sqlInsert();
			}			
			// list all the element in the BD
			ArrayList<GetSetId> al = sqlSelectAll();
			System.out.println("List if the " + al.size() + " elements in table " + tableName + " order by Name.");
			for(int i = 0; i < al.size(); i++)
				System.out.println((FirstName) al.get(i));

			// update one element to test the update transaction
			FirstName fn = (FirstName) al.get(1);
			// appends "xxx" to the name (this is just to test the Update transaction)
			fn.setName(fn.getName() + "xxx");
			fn.sqlUpdate();
			
			al = sqlSelectAll();
			System.out.println("List if the " + al.size() + " elements in table " + tableName + " after Update.");
			for(int i = 0; i < al.size(); i++)
				System.out.println((FirstName) al.get(i));
			
			// we delete the second of them to test the delete transaction
			((FirstName) al.get(1)).sqlDelete();
			// relist the contents
			al = sqlSelectAll();
			System.out.println("List if the " + al.size() + " elements in table " + tableName + " after delete.");
			for(int i = 0; i < al.size(); i++)
				System.out.println((FirstName) al.get(i));

		}
		else {  // Table already exist
			// list all the element in the BD
			ArrayList<GetSetId> al = sqlSelectAll();
			System.out.println("List if the " + al.size() + " elements in table " + tableName + " order by Name.");
			for(int i = 0; i < al.size(); i++)
				System.out.println((FirstName) al.get(i));
		}
	}
		
	// to return the single instance of this class
	static FirstNameTable getInstance() {
		return instance;
	}
	
	// to insert a new FirstName
	boolean sqlInsert(FirstName fn) {
		boolean status = false;
		try {
			// put the serialized  object by itself
			prstInsert.setObject(1, fn, Types.JAVA_OBJECT);
			// the uniqueId we do not know it yet so we set it to null
			prstInsert.setNull(2, Types.INTEGER);
			// we put the name bacause we want it unique case independant
			prstInsert.setString(3, fn.getName().toUpperCase());
			// perform the insert statement
			int nbChanged = statementExecute(prstInsert);
			status = nbChanged > 0;
			System.out.println("Statement execute " + prstInsert + " rows affected " + nbChanged + " status " + status);
		}
		catch(SQLException e) {
			System.out.println("FirstNameTable sqlInsert() exception: " + e);
		}
		return status;
	}
	
	// to insert a new FirstName
	boolean sqlUpdate(FirstName fn) {
		boolean status = false;
		try {
			// we put the name bacause we want it unique case independant
			prstUpdate.setString(1, fn.getName().toUpperCase());
			// put the serialized  object by itself
			prstUpdate.setObject(2, fn, Types.JAVA_OBJECT);
			// the uniqueId 
			prstUpdate.setInt(3, fn.getId());
			// perform the insert statement
			int nbChanged = statementExecute(prstUpdate);
			status = nbChanged > 0;
			System.out.println("Statement execute " + prstUpdate + " rows affected " + nbChanged + " status " + status);
		}
		catch(SQLException e) {
			System.out.println("FirstNameTable sqlUpdate() exception: " + e);
		}
		return status;
	}
	
	/** Returns the number of entries in the table */
	int getCount() {
		return getCount(tableName);
	}
	
	/** Returns a FirstName object by Id 
	 *  we call the standard method that returns a GetSetId and cast it */
	FirstName getById(int id) {
		return (FirstName) sqlGetById(id);
	}

}



Code for LastNameTable a few posts down because of truncation

This post has been edited by macosxnerd101: 17 August 2010 - 05:51 AM
Reason for edit:: Added note about LastNameTable


Is This A Good Question/Topic? 3
  • +

Replies To: Inserting Java objects into an HSQLdb database

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Posted 01 July 2009 - 08:20 PM

Now if you cut & paste all the classes and run the TestStandAlone class that is what you should see

Constructor of DbTable in StandAlone mode
HSQLdb driver correctly loaded.
Correctly connected in StandAlone mode.
queryExecute building prepStatement SELECT COUNT(*) FROM FirstNameTable; returns -22 java.sql.SQLException: Table not found in statement [SELECT COUNT(*) FROM FirstNameTable;]
GetCount() on FirstNameTable returns -1
statementExecute(Create Cached Table FirstNameTable (Obj OBJECT, Id INTEGER IDENTITY PRIMARY KEY, Name VARCHAR(1024) NOT NULL, UNIQUE (Id), UNIQUE (Name));) returns 0
statementExecute(ALTER TABLE FirstNameTable ALTER COLUMN Id RESTART WITH 1;) returns 0
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@bb7759[sql=[INSERT INTO FirstNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1989f84], [null], [PAUL]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@bb7759[sql=[INSERT INTO FirstNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1238bd2], [null], [BENOIT]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@bb7759[sql=[INSERT INTO FirstNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1198891], [null], [JOHN]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@bb7759[sql=[INSERT INTO FirstNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@17725c4], [null], [NEO]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@bb7759[sql=[INSERT INTO FirstNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@a761fe], [null], [CABBAGE]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@bb7759[sql=[INSERT INTO FirstNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@f0c0d3], [null], [HONEY]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@bb7759[sql=[INSERT INTO FirstNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@12cc95d], [null], [MIKE]]] rows affected 1 status true
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@157fb52[sql=[SELECT Obj, Id FROM FirstNameTable ORDER BY Name;]])
List if the 7 elements in table FirstNameTable order by Name.
[2] benoit
[5] cabbage
[6] honey
[3] john
[7] mike
[4] neo
[1] paul
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@1df280b[sql=[UPDATE FirstNameTable SET Name = ?, Obj = ? WHERE Id = ?;], parameters=[[CABBAGEXXX], [org.hsqldb.types.JavaObject@1be0f0a], [5]]] rows affected 1 status true
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@157fb52[sql=[SELECT Obj, Id FROM FirstNameTable ORDER BY Name;]])
List if the 7 elements in table FirstNameTable after Update.
[2] benoit
[5] cabbagexxx
[6] honey
[3] john
[7] mike
[4] neo
[1] paul
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@157fb52[sql=[SELECT Obj, Id FROM FirstNameTable ORDER BY Name;]])
List if the 6 elements in table FirstNameTable after delete.
[2] benoit
[6] honey
[3] john
[7] mike
[4] neo
[1] paul
queryExecute building prepStatement SELECT COUNT(*) FROM LastNameTable; returns -22 java.sql.SQLException: Table not found in statement [SELECT COUNT(*) FROM LastNameTable;]
GetCount() on LastNameTable returns -1
statementExecute(Create Cached Table LastNameTable (Obj OBJECT, Id INTEGER IDENTITY PRIMARY KEY, Name VARCHAR(1024) NOT NULL, UNIQUE (Id), UNIQUE (Name));) returns 0
statementExecute(ALTER TABLE LastNameTable ALTER COLUMN Id RESTART WITH 1;) returns 0
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@1f8c6df[sql=[INSERT INTO LastNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1c86be5], [null], [LAROCHELLE]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@1f8c6df[sql=[INSERT INTO LastNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@162dbb6], [null], [SHYHAWK33]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@1f8c6df[sql=[INSERT INTO LastNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@2ba11b], [null], [TIFFA]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@1f8c6df[sql=[INSERT INTO LastNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@8c1dd9], [null], [FOOLEY]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@1f8c6df[sql=[INSERT INTO LastNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1462851], [null], [MASTERMIND]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@1f8c6df[sql=[INSERT INTO LastNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@4ac00c], [null], [TRIGGA]]] rows affected 1 status true
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1865b28[sql=[SELECT Obj, Id FROM LastNameTable ORDER BY Name;]])
List if the 6 elements in table LastNameTable order by Name.
[4] fooley
[1] larochelle
[5] mastermind
[2] shyhawk33
[3] tiffa
[6] trigga
queryExecute building prepStatement SELECT COUNT(*) FROM FullNameTable; returns -22 java.sql.SQLException: Table not found in statement [SELECT COUNT(*) FROM FullNameTable;]
GetCount() on FullNameTable returns -1
statementExecute(Create Cached Table FullNameTable (Obj OBJECT, Id INTEGER IDENTITY PRIMARY KEY, FirstNameId INTEGER NOT NULL, LastNameId INTEGER NOT NULL, FOREIGN KEY (FirstNameId) REFERENCES FirstNameTable (Id), FOREIGN KEY (LastNameId) REFERENCES LastNameTable (Id), UNIQUE (Id));) returns 0
statementExecute(ALTER TABLE FullNameTable ALTER COLUMN Id RESTART WITH 1;) returns 0
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@157fb52[sql=[SELECT Obj, Id FROM FirstNameTable ORDER BY Name;]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1865b28[sql=[SELECT Obj, Id FROM LastNameTable ORDER BY Name;]])
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@110fe28], [null], [7], [3]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1d64c37], [null], [4], [3]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@12be1bd], [null], [1], [5]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1a5f739], [null], [1], [3]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@e6ff0d], [null], [4], [3]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1e97f9f], [null], [4], [3]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@288051], [null], [4], [2]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@ee7a14], [null], [3], [3]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@6cb8], [null], [3], [5]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@d81784], [null], [4], [3]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@142a80d], [null], [6], [3]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@139b78e], [null], [7], [4]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@d6a05e], [null], [6], [6]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@9df6f1], [null], [2], [1]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@b8bef7], [null], [4], [5]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@c1f10e], [null], [7], [6]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@4a6cbf], [null], [2], [4]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1a99561], [null], [7], [6]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1b000e7], [null], [3], [3]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@b01d43], [null], [7], [1]]] rows affected 1 status true
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@513cf0[sql=[SELECT Obj, Id FROM FullNameTable;]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[1]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[5]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[1]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[2]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[5]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[2]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[1]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[5]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[2]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[1]]])
List if the 20 elements in table FullNameTable.
tiffa, mike  26 years old
tiffa, neo  31 years old
mastermind, paul  43 years old
tiffa, paul  25 years old
tiffa, neo  28 years old
tiffa, neo  23 years old
shyhawk33, neo  42 years old
tiffa, john  49 years old
mastermind, john  32 years old
tiffa, neo  34 years old
tiffa, honey  21 years old
fooley, mike  49 years old
trigga, honey  38 years old
larochelle, benoit  27 years old
mastermind, neo  26 years old
trigga, mike  25 years old
fooley, benoit  39 years old
trigga, mike  47 years old
tiffa, john  45 years old
larochelle, mike  39 years old
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@513cf0[sql=[SELECT Obj, Id FROM FullNameTable;]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[1]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[5]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[1]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[2]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[5]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[2]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[1]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[5]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[2]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[1]]])
List of the 8 FullName between 10 and 30 yeras old.
tiffa, mike  26 years old
tiffa, paul  25 years old
tiffa, neo  28 years old
tiffa, neo  23 years old
tiffa, honey  21 years old
larochelle, benoit  27 years old
mastermind, neo  26 years old
trigga, mike  25 years old


Was This Post Helpful? 3
  • +
  • -

#3 Munkon  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 61
  • Joined: 13-August 09

Posted 07 September 2009 - 03:19 PM

Hi pbl,

This is the tutorial I've been looking for!
Thank you very much for the time and effort..

Unfortunatly, the code is not finished,

the LastNameTable code is cut and the FullNameTable code is missing..
In addition, there is no single main method in this tutorial..

Please, I need the rest of it..

Thanks again..

Munkon.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Posted 23 November 2009 - 08:44 PM

View PostMunkon, on 7 Sep, 2009 - 02:19 PM, said:

Hi pbl,

This is the tutorial I've been looking for!
Thank you very much for the time and effort..

Unfortunatly, the code is not finished,

the LastNameTable code is cut and the FullNameTable code is missing..
In addition, there is no single main method in this tutorial..

Please, I need the rest of it..

Thanks again..

Munkon.

I tried many times to add the missing code but it does not work
there is probably a limit on the number of bytes a tutorial can have
I'll send you the comple code my email
Was This Post Helpful? 1
  • +
  • -

#5 Munkon  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 61
  • Joined: 13-August 09

Posted 24 November 2009 - 12:24 AM

Thanx man, but you already did on september 9th..

Have a great day.
Was This Post Helpful? 0
  • +
  • -

#6 Guest_Frank Tveter*


Reputation:

Posted 16 August 2010 - 05:53 AM

View Postpbl, on 23 November 2009 - 07:44 PM, said:

View PostMunkon, on 7 Sep, 2009 - 02:19 PM, said:

Hi pbl,

This is the tutorial I've been looking for!
Thank you very much for the time and effort..

Unfortunatly, the code is not finished,

the LastNameTable code is cut and the FullNameTable code is missing..
In addition, there is no single main method in this tutorial..

Please, I need the rest of it..

Thanks again..

Munkon.

I tried many times to add the missing code but it does not work
there is probably a limit on the number of bytes a tutorial can have
I'll send you the comple code my email


Hi,

Excellent tutorial - right up to the point where it was truncated!

Is the complete code available on the Net somewhere? If not, could you please post the remaining fragments?

Thanks,
Frank T.
Was This Post Helpful? 0

#7 Munkon  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 61
  • Joined: 13-August 09

Posted 16 August 2010 - 06:25 AM

Hi Frank,

Write your E-Mail and I'll send you the mail PBL sent me.
Have a great day.

Munkon.
Was This Post Helpful? 0
  • +
  • -

#8 Guest_Frank Tveter*


Reputation:

Posted 16 August 2010 - 08:37 AM

View PostMunkon, on 16 August 2010 - 05:25 AM, said:

Hi Frank,

Write your E-Mail and I'll send you the mail PBL sent me.
Have a great day.

Munkon.


Hi Munkon,

Thanks for the swift reply.

frank,tveter at met,no

Thanks again,
Frank T.
Was This Post Helpful? 0

#9 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10442
  • View blog
  • Posts: 38,676
  • Joined: 27-December 08

Posted 16 August 2010 - 08:50 AM

I've PM'd pbl and asked him if he can post the remaining code on a separate post. :)
Was This Post Helpful? 0
  • +
  • -

#10 Munkon  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 61
  • Joined: 13-August 09

Posted 16 August 2010 - 12:27 PM

Hi again,

Please write in English...
I understand only English and bad English..

You were signed as guest so I couldn't write you in private.

The question is: "do you want the files or not?"..

Munkon.
Was This Post Helpful? 0
  • +
  • -

#11 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Posted 16 August 2010 - 07:58 PM

Here is the code for LastNameTable

import java.sql.*;
import java.util.*;

// handles the LastNameTable
public class LastNameTable extends DbTable{

	// this table is a Singleton
	private static LastNameTable instance;
	// predefined FirstName to be used if DB is empty
	private static final String[] fName = {"larochelle", "shyhawk33", "tiffa", "fooley", "mastermind", "trigga"};
	// Table name and is create statement
	private static final String tableName = "LastNameTable";
	// by default HSQLdb creates in memory table we need the keyword "Cached Table" to make it on disk
	private static final String createTable = 
		"Create Cached Table " + tableName + " (" +
		"Obj OBJECT, " +							// the Object implementing GetSetId()
		"Id INTEGER IDENTITY PRIMARY KEY, " + 		// unique Id within that table
		"Name VARCHAR(1024) NOT NULL, " +			// the name unique (not case sensitive) within the table
		"UNIQUE (Id), " +
		"UNIQUE (Name)" +
		");";
	
	/*
	 * This class handles the SQL requests to the FirstNameTable
	 */
	LastNameTable() {
		instance = this;
		// a flag to inform us if the table existed or not
		// if it didn't exist we will populate it
		boolean tableExisted = true;
		// we check if the table exist if not we create it
		if(getCount() == -1) {
			// flag table creation
			tableExisted = false;
			statementExecute(createTable);			// lets create it
			// I hate tableId starting at 0 (personal preference so I set the Id to start at 1)
	 		statementExecute("ALTER TABLE " + tableName + " ALTER COLUMN Id RESTART WITH 1;");  		  		
	 	}
		
		// we create our PreparedStatements
		try {
			prstInsert = con.prepareStatement("INSERT INTO " + tableName + " (Obj, Id, Name) VALUES (?, ?, ?)");
			prstUpdate = con.prepareStatement("UPDATE " + tableName + " SET Name = ?, Obj = ? WHERE Id = ?;");
			prstDelete = con.prepareStatement("DELETE FROM " + tableName + " WHERE Id = ?;");
			prstGetById = con.prepareStatement("SELECT Obj FROM " + tableName + " WHERE Id = ?;");
			prstSelectAll = con.prepareStatement("SELECT Obj, Id FROM " + tableName + " ORDER BY Name;");
		}
		catch(SQLException e) {
			System.out.println("Problem creating PreparedStatement for " + tableName + ".");
			throw new IllegalStateException("Problem creating PreparedStatement for " + tableName + ".");
		}
		
		// now if the table didn't exist we fill it with our predefined elements
		if(!tableExisted) {
			// loopt throught our predifed name to initialize the table
			for(int i = 0; i < fName.length; i++) {
				// create FirtName object
				LastName ln = new LastName(fName[i]);
				// insert it into DB
				ln.sqlInsert();
			}			
		}
		
		// list all the element in the BD
		ArrayList<GetSetId> al = sqlSelectAll();
		System.out.println("List if the " + al.size() + " elements in table " + tableName + " order by Name.");
		for(int i = 0; i < al.size(); i++)
			System.out.println((LastName) al.get(i));
		
	}
		
	// to return the single instance of this class
	static LastNameTable getInstance() {
		return instance;
	}
	
	// to insert a new FirstName
	boolean sqlInsert(LastName fn) {
		boolean status = false;
		try {
			// put the serialized  object by itself
			prstInsert.setObject(1, fn, Types.JAVA_OBJECT);
			// the uniqueId we do not know it yet so we set it to null
			prstInsert.setNull(2, Types.INTEGER);
			// we put the name bacause we want it unique case independant
			prstInsert.setString(3, fn.getName().toUpperCase());
			// perform the insert statement
			int nbChanged = statementExecute(prstInsert);
			status = nbChanged > 0;
			System.out.println("Statement execute " + prstInsert + " rows affected " + nbChanged + " status " + status);
		}
		catch(SQLException e) {
			System.out.println("LastNameTable sqlInsert() exception: " + e);
		}
		return status;
	}
	
	// to insert a new FirstName or LastName
	boolean sqlUpdate(LastName fn) {
		boolean status = false;
		try {
			// we put the name bacause we want it unique case independant
			prstUpdate.setString(1, fn.getName().toUpperCase());
			// put the serialized  object by itself
			prstUpdate.setObject(2, fn, Types.JAVA_OBJECT);
			// the uniqueId 
			prstUpdate.setInt(3, fn.getId());
			// perform the insert statement
			int nbChanged = statementExecute(prstUpdate);
			status = nbChanged > 0;
			System.out.println("Statement execute " + prstUpdate + " rows affected " + nbChanged + " status " + status);
		}
		catch(SQLException e) {
			System.out.println("LastNameTable sqlUpdate() exception: " + e);
		}
		return status;
	}
	
	/** Returns the number of entries in the table */
	int getCount() {
		return getCount(tableName);
	}
	
	/** Returns a LastName object by Id 
	 *  we call the standard method that returns a GetSetId and cast it */
	LastName getById(int id) {
		return (LastName) sqlGetById(id);
	}


}



And the FullNameTable


import java.sql.*;
import java.util.*;

// handles the FullNameTable
public class FullNameTable extends DbTable{

	// this table is a Singleton
	private static FullNameTable instance;
	// Table name and is create statement
	private static final String tableName = "FullNameTable";
	// by default HSQLdb creates in memory table we need the keyword "Cached Table" to make it on disk
	private static final String createTable = 
		"Create Cached Table " + tableName + " (" +
		"Obj OBJECT, " +							// the Object implementing GetSetId()
		"Id INTEGER IDENTITY PRIMARY KEY, " + 		// unique Id within that table
		"FirstNameId INTEGER NOT NULL, " +
		"LastNameId INTEGER NOT NULL, " +
		"FOREIGN KEY (FirstNameId) REFERENCES FirstNameTable (Id), " +
		"FOREIGN KEY (LastNameId) REFERENCES LastNameTable (Id), " +
		"UNIQUE (Id)" +
		");";
	
	/*
	 * This class handles the SQL requests to the FirstNameTable
	 */
	FullNameTable() {
		instance = this;
		// a flag to inform us if the table existed or not
		// if it didn't exist we will populate it
		boolean tableExisted = true;
		// we check if the table exist if not we create it
		if(getCount(tableName) == -1) {
			// flag table creation
			tableExisted = false;
			statementExecute(createTable);			// lets create it
			// I hate tableId starting at 0 (personal preference so I set the Id to start at 1)
	 		statementExecute("ALTER TABLE " + tableName + " ALTER COLUMN Id RESTART WITH 1;");  		  		
	 	}

		// we create our PreparedStatements
		try {
			prstInsert = con.prepareStatement("INSERT INTO " + tableName + " (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)");
			prstUpdate = con.prepareStatement("UPDATE " + tableName + " SET Obj = ?, FirstNameId = ?, LastNameId = ? WHERE Id = ?;");
			prstDelete = con.prepareStatement("DELETE FROM " + tableName + " WHERE Id = ?;");
			prstGetById = con.prepareStatement("SELECT Obj FROM " + tableName + " WHERE Id = ?;");
			prstSelectAll = con.prepareStatement("SELECT Obj, Id FROM " + tableName + ";");
		}
		catch(SQLException e) {
			System.out.println("Problem creating PreparedStatement for " + tableName + ".");
			throw new IllegalStateException("Problem creating PreparedStatement for " + tableName + ".");
		}
		
		// now if the table didn't exist we will fill it with our predefined elements
		if(!tableExisted) {
			// we will create randomly a few entries
			Random ran = new Random();
			// get all available FirstName and LastName
			ArrayList<GetSetId> alfn = FirstNameTable.getInstance().sqlSelectAll();
			ArrayList<GetSetId> alln = LastNameTable.getInstance().sqlSelectAll();
			// loop to initialize the table
			for(int i = 0; i < 20; i++) {
				// fetch randomly a FirtName and a LastName object
				FirstName fn = (FirstName) alfn.get(ran.nextInt(alfn.size()));
				LastName ln = (LastName) alln.get(ran.nextInt(alln.size()));
				// create a full name object with a random age
				int age = ran.nextInt(30) + 20;
				FullName fullName = new FullName(fn, ln, age);
				// insert it into DB
				fullName.sqlInsert();
			}			
		}
		
		// list all the element in the BD
		ArrayList<GetSetId> al = sqlSelectAll();
		System.out.println("List if the " + al.size() + " elements in table " + tableName + ".");
		for(int i = 0; i < al.size(); i++)
			System.out.println((FullName) al.get(i));
		
		// list the FullName between 10 and 30 years old
		ArrayList<FullName> byAge = getAgeBetween(10, 30);
		System.out.println("List of the " + byAge.size() + " FullName between 10 and 30 yeras old.");
		for(FullName person : byAge)
			System.out.println(person);
	}
		
	// to return the single instance of this class
	static FullNameTable getInstance() {
		return instance;
	}
	
	// to insert a new FullName
	boolean sqlInsert(FullName fn) {
		boolean status = false;
		try {
			// put the serialized  object by itself
			prstInsert.setObject(1, fn, Types.JAVA_OBJECT);
			// the uniqueId we do not know it yet so we set it to null
			prstInsert.setNull(2, Types.INTEGER);
			// the 2 foreigns keys
			prstInsert.setInt(3, fn.getFirstNameId());
			prstInsert.setInt(4, fn.getLastNameId());
			// perform the insert statement
			int nbChanged = statementExecute(prstInsert);
			status = nbChanged > 0;
			System.out.println("Statement execute " + prstInsert + " rows affected " + nbChanged + " status " + status);
		}
		catch(SQLException e) {
			System.out.println("FullNameTable sqlInsert() exception: " + e);
		}
		return status;
	}
	
	// to insert a new FirstName or LastName
	boolean sqlUpdate(FullName fn) {
		boolean status = false;
		try {
			// put the serialized  object by itself
			prstUpdate.setObject(1, fn, Types.JAVA_OBJECT);
			// we put the name bacause we want it unique case independant
			prstUpdate.setInt(2, fn.getFirstNameId());
			prstUpdate.setInt(3, fn.getLastNameId());
			// the uniqueId 
			prstUpdate.setInt(3, fn.getId());
			// perform the insert statement
			int nbChanged = statementExecute(prstUpdate);
			status = nbChanged > 0;
			System.out.println("Statement execute " + prstUpdate + " rows affected " + nbChanged + " status " + status);
		}
		catch(SQLException e) {
			System.out.println("FullNameTable sqlUpdate() exception: " + e);
		}
		return status;
	}

	/** Returns the number of entries in the table */
	int getCount() {
		return getCount(tableName);
	}
	
	/** Returns a FullName object by Id 
	 *  we call the standard method that returns a GetSetId and cast it */
	FullName getById(int id) {
		return (FullName) sqlGetById(id);
	}

	/* This method demonstrate how to do a "select" on an instance variable of an object
	 * even if this field is not in the Database column
	 * here we select on the age. The age is on the object but not in a column
	 */
	ArrayList<FullName> getAgeBetween(int from, int to) {
		ArrayList<FullName> al = new ArrayList<FullName>();
		// get all our FullName
		ArrayList<GetSetId> selectAll = sqlSelectAll();
		for(int i = 0; i < selectAll.size(); i++) {
			// get the FullName object
			FullName fullName = (FullName) selectAll.get(i);
			// extract its age
			int age = fullName.getAge();
			// if criteria match add it to ArrayList
			if(age >= from && age <= to)
				al.add(fullName);
		}
		// return the object that match the criteria
		return al;
	}

}


Was This Post Helpful? 0
  • +
  • -

#12 Guest_Frank Tveter*


Reputation:

Posted 17 August 2010 - 12:28 AM

View PostMunkon, on 16 August 2010 - 11:27 AM, said:

Hi again,

Please write in English...
I understand only English and bad English..

You were signed as guest so I couldn't write you in private.

The question is: "do you want the files or not?"..

Munkon.


Hi Munkon,

The "very bad english" was my e-mail address. ;-)

Anyway, Paul-Benoit Larochelle (pbl) already posted the code I requested below.

Thanks,
Frank T.
Was This Post Helpful? 0

#13 Guest_Frank Tveter*


Reputation:

Posted 20 August 2010 - 12:55 AM

View Postpbl, on 16 August 2010 - 06:58 PM, said:

Here is the code for LastNameTable
...


Hi pbl,

Thanks for the code. :-)

I have 2 questions:

1) When using the standalone database (file:), I have understood that there is about a 10ms delay in writing to file. If the program terminates before the write is completed, the database is not updated. How is your standalone database "shutdown" handled in this respect?

2) Do you run one of the Table constructors in the main program? (If not, how is the DbTable.Instance populated?)

Thanks,
Frank T.
Was This Post Helpful? 0

#14 Vorms  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-May 11

Posted 27 May 2011 - 05:59 AM

About hsql tutorial.

thanks for your very nice tutorial !

Can you please send me the main method ?


Many thanks in advance.

Thierry vorms
<Removed>

This post has been edited by macosxnerd101: 28 May 2011 - 03:46 PM
Reason for edit:: Email removed per site policies.

Was This Post Helpful? 0
  • +
  • -

#15 tfoman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-March 13

Posted 29 March 2013 - 02:30 AM

Thanks for an interesting article!
Sorry i'm new here and made a small mistake when posting my question (posting your article once Moore instead).
What i'm really interested of is if it's possible you could share the "TestStandAlone class" to be able to test your classes about HSQLdb.

Regards
Tommy
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2