public MessageThread loadMessageThread(int threadId) throws SQLException {

    if (connection == null) {
      this.initConnection();
    }

    String query = "select * from MessageThread where id = ?";
    PreparedStatement statement = connection.prepareStatement(query);
    statement.setInt(1, threadId);

    MessageThread thread = null;

    ResultSet set = statement.executeQuery();
    if (set.next()) {
      thread = new MessageThread();

      thread.setId(set.getInt("id"));
      thread.setName(set.getString("name"));
      thread.setUrl(set.getString("url"));
    }

    set.close();
    statement.close();

    return thread;
  }
  public MessageThread loadMessageThreadByName(String name) {

    if (name == null) return null;

    if (connection == null) {
      this.initConnection();
    }

    try {
      String query = "select * from MessageThread where name like ?";
      PreparedStatement statement = connection.prepareStatement(query);
      statement.setString(1, name);

      MessageThread thread = null;

      ResultSet set = statement.executeQuery();
      if (set.next()) {
        thread = new MessageThread();

        thread.setId(set.getInt("id"));
        thread.setName(set.getString("name"));
        thread.setUrl(set.getString("url"));
      }

      set.close();
      statement.close();

      return thread;

    } catch (SQLException e) {
      e.printStackTrace();
    }

    return null;
  }
  public MessageThread getMessageThread(int messageId) throws IllegalArgumentException {

    try {
      Statement s0 = connection.createStatement();
      ResultSet set0 =
          s0.executeQuery(
              "select t.* from MessageThread t, Message m where m.id = "
                  + messageId
                  + " and m.threadID = t.id");
      if (!set0.next()) throw new IllegalArgumentException("Invalid message id : " + messageId);

      MessageThread thread = new MessageThread();
      thread.setId(set0.getInt("id"));
      thread.setMessageBoard(null);
      thread.setMessages(null);
      thread.setName(set0.getString("name"));
      thread.setUrl(set0.getString("url"));

      set0.close();
      s0.close();

      return thread;

    } catch (SQLException e) {
      e.printStackTrace();
    }

    return null;
  }