[英]How to insert date selected separately into mysql using Java(JSP)
In my project I want to save date which is read separately as day,month,year by using a select box. 在我的项目中,我想通过使用选择框将日期分别保存为日,月,年。 The 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 savetask函数是
public int savetask(String qnid,String userid,String start,String end)
{
int n=0;
try{
String sql="insert into 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 it is not inserting values to the table task
The table format for task is 但这不是在表
task
插入值。 task
的表格式为
task_id int (Auto increment)
user_id int
question_id int
start_date date
end_date date
status int
First of all, Your sql line is invalid.Missing bracket in the end. 首先,您的sql行无效。最后没有括号。
String sql="insert into task(user_id,question_id,start_date,end_date,status)values
('"+qnid+"','"+userid+"','"+start+"','"+end+"',0");
^
one more syntax error is there is no need for "
after the 0
in the end since it is an int
(realized after you updated the column structure). 另外一个语法错误是,由于它是一个
int
(在更新列结构之后实现),因此最后不需要在0
后加上"
。
Still if you face further exceptions,provide the stack trace. 如果仍然遇到其他异常,请提供堆栈跟踪。
Update(comment that helpful to resolve the issue): 更新(有助于解决此问题的评论):
What you have to do is after the line String sql = ...
,Put System.out.println(sql)
So it prints the query
in console.Pick that line and fire it on your Data base query manager.And see for any syntax errors. 您需要做的是在
String sql = ...
,放入System.out.println(sql)
,以便在控制台中打印query
。选择该行并将其在数据库查询管理器中触发。语法错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.