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.
if have concern growing number of arguments there possible solutions
- pass map in can pass number of arguments want in form of key-value pair required
- 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
Post a Comment