public void persistConnection(Connection connection) throws PersistenceException {
  MqttConnectOptions conOpts=connection.getConnectionOptions();
  MqttMessage lastWill=conOpts.getWillMessage();
  SQLiteDatabase db=getWritableDatabase();
  ContentValues values=new ContentValues();
  values.put(COLUMN_HOST,connection.getHostName());
  values.put(COLUMN_port,connection.getPort());
  values.put(COLUMN_client_ID,connection.getId());
  values.put(COLUMN_ssl,connection.isSSL());
  values.put(COLUMN_KEEP_ALIVE,conOpts.getKeepAliveInterval());
  values.put(COLUMN_TIME_OUT,conOpts.getConnectionTimeout());
  values.put(COLUMN_USER_NAME,conOpts.getUserName());
  values.put(COLUMN_TOPIC,conOpts.getWillDestination());
  char[] password=conOpts.getPassword();
  values.put(COLUMN_CLEAN_SESSION,conOpts.isCleanSession() ? 1 : 0);
  values.put(COLUMN_PASSWORD,password != null ? String.valueOf(password) : null);
  values.put(COLUMN_MESSAGE,lastWill != null ? new String(lastWill.getPayload()) : null);
  values.put(COLUMN_QOS,lastWill != null ? lastWill.getQos() : 0);
  if (lastWill == null) {
    values.put(COLUMN_RETAINED,0);
  }
 else {
    values.put(COLUMN_RETAINED,lastWill.isRetained() ? 1 : 0);
  }
  long newRowId=db.insert(TABLE_CONNECTIONS,null,values);
  db.close();
  if (newRowId == -1) {
    throw new PersistenceException("Failed to persist connection: " + connection.handle());
  }
 else {
    connection.assignPersistenceId(newRowId);
  }
}

public void persistConnection ( Connection connection ) throws PersistenceException { MqttConnectOptions conOpts = connection . getConnectionOptions ( ) ; MqttMessage lastWill = conOpts . getWillMessage ( ) ; SQLiteDatabase db = getWritableDatabase ( ) ; ContentValues values = new ContentValues ( ) ; values . put ( COLUMN_HOST , connection . getHostName ( ) ) ; values . put ( COLUMN_port , connection . getPort ( ) ) ; values . put ( COLUMN_client_ID , connection . getId ( ) ) ; values . put ( COLUMN_ssl , connection . isSSL ( ) ) ; values . put ( COLUMN_KEEP_ALIVE , conOpts . getKeepAliveInterval ( ) ) ; values . put ( COLUMN_TIME_OUT , conOpts . getConnectionTimeout ( ) ) ; values . put ( COLUMN_USER_NAME , conOpts . getUserName ( ) ) ; values . put ( COLUMN_TOPIC , conOpts . getWillDestination ( ) ) ; char [ ] password = conOpts . getPassword ( ) ; values . put ( COLUMN_CLEAN_SESSION , conOpts . isCleanSession ( ) ? 1 : 0 ) ; values . put ( COLUMN_PASSWORD , password != null ? String . valueOf ( password ) : null ) ; values . put ( COLUMN_MESSAGE , lastWill != null ? new String ( lastWill . getPayload ( ) ) : null ) ; values . put ( COLUMN_QOS , lastWill != null ? lastWill . getQos ( ) : 0 ) ; if ( lastWill == null ) { values . put ( COLUMN_RETAINED , 0 ) ; } else { values . put ( COLUMN_RETAINED , lastWill . isRetained ( ) ? 1 : 0 ) ; } long newRowId = db . insert ( TABLE_CONNECTIONS , null , values ) ; db . close ( ) ; if ( newRowId == - 1 ) { throw new PersistenceException ( "Failed to persist connection: " + connection . handle ( ) ) ; } else { connection . assignPersistenceId ( newRowId ) ; } }
persist a connection to the database
