private String getLastId() throws SQLException, RemoteException
	{
    checkConnection();

		Statement stmt = null;
		ResultSet rs = null;
		try {

      String tableName = getTableName();
      String idField   = getIDField();
      if (this.upper)
      {
        tableName = tableName.toUpperCase();
        idField   = idField.toUpperCase();
      }
      
			stmt = getConnection().createStatement();
			rs = stmt.executeQuery("select max(" + idField + ") from " + tableName);
			if (!rs.next())
        throw new SQLException("select max(id) returned empty resultset");
			return rs.getString(1);
		}
		finally
		{
		  if (rs != null) {
		    try {
		      rs.close();
		    } catch (SQLException se) {/*useless*/}
		  }
      if (stmt != null) {
        try {
          stmt.close();
        } catch (SQLException se) {/*useless*/}
      }
		}
	}