Re: need cursor info



On 25.11.2006 18:41, Martin Gregorie wrote:
gk wrote:
rs.moveToInsertRow(); // moves cursor to the insert row
rs.updateString(1, "AINSWORTH"); // updates the
// first column of the insert row to be AINSWORTH
rs.updateInt(2,35); // updates the second column to be 35
rs.updateBoolean(3, true); // updates the third column to true
rs.insertRow();
rs.moveToCurrentRow();

This is bad practice.

You should never hard-code column numbers into a program because, if you do, your program will mysteriously fail if the columns in the table are re-ordered or additional columns are added. Always explicitly name columns or use the findColumn() method.

I am sorry, but you are wrong here. Nothing will break if the table layout changes as long as you enumerate columns explicitly. Accessing columns by index is as safe as using the name and usually faster than by name. Doing so is perfectly sane since you create the query. When doing ResultSet rs = st.executeQuery("select foo, bar from tab") you always know that column 1 is "foo" and column 2 is "bar". The bad practice is this:

> Same objection goes for the
common short-hand "select * from ..." form of query.

No, this is a different case. "select *" is unstable, i.e. it will change layout if the schema of the queried table is changed.

Btw, indexing by name and findColumn() also break if columns are renamed.

Kind regards

robert
.



Relevant Pages

  • Re: Keynote
    ... I'm promised that iMovie 09 is actually useful again - iMovie was the ... Updates to iLife and iWork were utterly predictable (that's not to say ... This is a big win for both principle and practice. ... the victory over DRM on the iTMS is a great thing (even though ...
    (uk.comp.sys.mac)
  • Re: Many KBxxxxx.log failure files after trying to patch SP2
    ... Security Updates Scan Results ... Issue: Windows Security Updates ... Score: Best practice ...
    (microsoft.public.windowsupdate)
  • Re: Create An Automated Install CD?
    ... practice, ... >> not exactly sure which updates to include (meaning, ... >> them, take them from my 'Windows' folder, or ...
    (microsoft.public.windowsxp.setup_deployment)
  • Re: Do current Office 2004 cds have a "newer" version on them??
    ... I can't speak to MS practice, *specifically*, but expect they do the ... Later production runs incorporate the most current update of the ... packaging changes only occur for major releases, not interim updates. ...
    (microsoft.public.mac.office)

Loading