java - How to use the update statement in my jsp -
i having update statament in jsp. problem when changing whole fields in jsp , executed update statament, db updated, when updating field, other fields "" in sql statement. also, having problem having miss match in date, best format applied in sql statement in jsp.
for first problem: html code:
<select size="1" name="nationality" class="content"> <option selected value="<%=nationality%>"><%=nationality%></option> <% try { resultset rs=null; statement st1=null; string query = "select country_code, nationality_name nationality_lkup "; st1 = conn1.createstatement(); rs = st1.executequery(query); while(rs.next()) { %> <option value="<%=rs.getstring("country_code")%>" > <%=rs.getstring("nationality_name")%></option> <% } } catch (exception e) { e.printstacktrace(); } %> </select>
and update statament is:
string sz_sqlupdate = "update cir set"; z_sqlupdate = sz_sqlupdate + " , nationality ='"+nationality+"'";
also, how can deal date format in update statement?
but when updating field, other fields "" in sql statement.
i not sure if complete code (the sql shown far have produced sql syntax exception when executed), should @ least not put comma between set
, first column name.
if sql syntactically valid, may mean variables empty @ moment access them inline in sql statement. should either prefill variables or leave associated columns away sql query if don't need updated.
also, having problem having miss match in date, best format applied in sql statement in jsp.
the best approach not worry format , set fullworthy java object representing timestamp in sql statement using preparedstatement#settimestamp()
. see recent question.
that said, have 2 major problems in code.
raw java code in jsp files should avoided. leads trouble in colors, not you, others, , in future.
this sql sensitive sql injection attacks , jdbc code prone resource leaking.
it's going long story explain how things properly, here few links go through picture how things properly.
- beginning , intermediate jsp/servlet tutorials
- how avoid java code in jsp files
- jsp/servlet best practices
- using prepared statements in jdbc
you should throw away old fashioned jsp tutorial/book you're reading.
Comments
Post a Comment