java - How to pass object field in DAO? -


i created daos entities. , have problem: need pass object's field in methods. example:

@override public void updatebyid(pricetrack pricetrack, int id) throws dbexception {     preparedstatement ps = null;     try {         conn.settransactionisolation(connection.transaction_serializable);         conn.setautocommit(false);         ps = conn.preparestatement(update_by_id);         ps.setint(1, pricetrack.getoldprice());         ps.setint(2, pricetrack.getnewprice());         ps.setdate(3, new java.sql.date(pricetrack.getlastupdatedprice().gettime()));         // todo - pass appartment id         ps.setobject(4, new apartment());         ps.executeupdate();         conn.commit();     } catch (sqlexception e) {         jdbcutils.rollbackquitely(conn);         throw new dbexception("cannot execute sql = '" + update_by_id + "'", e);     } {         jdbcutils.closequitely(ps);         jdbcutils.closequitely(conn);     } } 

here need pass corresponding aparment_id value. creating new apartment() wrong.

content of update_by_id:

    public static final string update_by_id = "update price_track set old_price=?, new_price=?, lastupdated_price=?, apartment_id=?"; 

what best way it?

here diagram, shows connection. enter image description here

if have concern growing number of arguments there possible solutions

  1. pass map in can pass number of arguments want in form of key-value pair required
  2. pass object when arguments being passed many , part of form correlate fields of class , supplied in form of populated object

which case go depends on way getting data , anticipation of getting more fields in future


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -