Re: need cursor info
- From: Robert Klemme <shortcutter@xxxxxxxxxxxxxx>
- Date: Sat, 25 Nov 2006 21:55:56 +0100
On 25.11.2006 18:41, Martin Gregorie wrote:
gk wrote:rs.moveToInsertRow(); // moves cursor to the insert rowThis is bad practice.
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();
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
.
- Follow-Ups:
- Re: need cursor info
- From: Martin Gregorie
- Re: need cursor info
- References:
- need cursor info
- From: gk
- Re: need cursor info
- From: RedGrittyBrick
- Re: need cursor info
- From: gk
- Re: need cursor info
- From: Robert Klemme
- Re: need cursor info
- From: gk
- Re: need cursor info
- From: Martin Gregorie
- need cursor info
- Prev by Date: Re: Giving an application a window icon in a sensible way
- Next by Date: Re: Peterson's Algorithm in java, sequencial instruction execution ?
- Previous by thread: Re: need cursor info
- Next by thread: Re: need cursor info
- Index(es):
Relevant Pages
|
Loading