How to insert date selected separately into mysql using Java(JSP) -
in project want save date read separately day,month,year using select box. code used is
<% string value=null; string[] h=null; h=request.getparametervalues("qns[]"); string expert=request.getparameter("expert"); int sday=integer.parseint(request.getparameter("sday")); int smonth=integer.parseint(request.getparameter("smonth")); int syear=integer.parseint(request.getparameter("syear")); int eday=integer.parseint(request.getparameter("eday")); int emonth=integer.parseint(request.getparameter("emonth")); int eyear=integer.parseint(request.getparameter("eyear")); string start=syear+"-"+smonth+"-"+sday; string end=eyear+"-"+emonth+"-"+eday; for(int i=0;i<h.length;i++) { s.savetask(h[1],expert,start,end); } %>
the savetask function is
public int savetask(string qnid,string userid,string start,string end) { int n=0; try{ string sql="insert task(user_id,question_id,start_date,end_date,status)values('"+qnid+"','"+userid+"','"+start+"','"+end+"',0"; n = db.modifyingqueries(sql); } catch(exception e){ } return n; }
but not inserting values table task
table format task is
task_id int (auto increment) user_id int question_id int start_date date end_date date status int
first of all, sql line invalid.missing bracket in end.
string sql="insert task(user_id,question_id,start_date,end_date,status)values ('"+qnid+"','"+userid+"','"+start+"','"+end+"',0"); ^
one more syntax error there no need "
after 0
in end since int
(realized after updated column structure).
still if face further exceptions,provide stack trace.
update(comment helpful resolve issue):
what have after line string sql = ...
,put system.out.println(sql)
prints query
in console.pick line , fire on data base query manager.and see syntax errors.
Comments
Post a Comment