私は次の機能を持っています:
public Map<Integer, Product> fetchAllProducts() {
  Map<Integer, Product> pArr = new HashMap();
  try {
     Statement st = conn.createStatement();
     ResultSet rs = st.executeQuery("SELECT id, intro, content, price FROM Product");
     while (rs.next()) {
       pArr.put(rs.getInt("id"), new Product(rs));
     }
     st.close();
  } catch (SQLException ex) {
   //...
  }
  return pArr;
}
mySQL テーブルからすべての行を取得し、行Productごとに新しいProductクラスを作成します。製品コンストラクター:
 public Product(ResultSet rs) {
    try {
       price = rs.getInt("price");
       content = rs.getString("content");
       intro = rs.getString("intro");
    } catch (SQLException ex) {
       //...
    }
   }
私の質問は: 結果列を の変数に割り当てるより良い方法はありますProductか? コードprice = rs.getInt("price");などは冗長に見えますね。クエリステートメントをSELECT intro, content, tax, delivery FROM ...コンストラクターに変更すると、コンストラクター内の適切な変数 (つまり、イントロ、コンテンツ、税金、配送) に自動的に割り当てられます。これはJavaで実行できますか、それとも私は夢を見ているだけですか?