从数据表请求未知参数'2'

时间:2013-04-08 01:08:34

标签: java jquery json datatable

我正在使用Jquery Datatable进行服务器端处理,以便处理我的所有数据。我的参数'2'是一个日期,我以字符串形式输入,转换为要添加到数据库的日期,但是,再次使用字符串显示到网页。这适用于'GetData'过程。但是,当我使用“AddData”输入新数据集时,我在标题中收到错误。似乎只有处理Date的两列抛出了这个错误,行的其余部分都被写入了。刷新页面后,一切都恢复正常。

这是我的数据表脚本:

var i = 0;
        $(document).ready(function(){
            oTable = $("#datatables").dataTable({
                        "aoColumns" : [
                            { "sName" : attendingPhysician" },
                            { "sName" : "physicianName" },
                            { "sName" : "dateStart" },
                            { "sName" : "dateEnd" },
                            { "sName" : "teamNumber" }
                         ],
                        "sAjaxSource" : 'teamassignmentdata',
                        "sServerMethod": "GET",
                        "fnDrawCallback" : function(oSettings) {
                            //The call to makeEditable is set here to make sure all the data are loaded
                            i++;
                            if(i == 1) {
                                this.makeEditable({
                                    sUpdateURL : 'UpdateTeamAssignmentData',
                                    sAddNewRowFormId: "formAddNewRow",
                                    sAddNewRowButtonId: "btnAddNewRow",
                                    sAddNewRowOkButtonId: "btnAddNewRowOk",
                                    sAddNewRowCancelButtonId: "btnAddNewRowCancel",
                                    sAddURL: "AddTeamAssignmentData",
                                    sAddHttpMethod: "POST",
                                    aoColumns : [
                                         {},    //physician number; default editing 
                                         {},    //physician name; default editing
                                         {      //date start; datepicker
                                            type : 'datepicker',
                                             datepicker : {
                                               dateFormat : 'yy-mm-dd'
                                             }
                                         },             
                                         {
                                            type : 'datepicker',
                                             datepicker : {
                                               dateFormat : 'yy-mm-dd'
                                             }
                                         },     //date end; datepicker
                                         {  //team number; no editing
                                            indicator: 'Saving...',
                                            tooltip: 'Click to edit team number',
                                            loadtext: 'loading...',
                                            type: 'select',
                                            onblur: 'submit',
                                            data: "{'5':'5','6':'6','7':'7','8':'8','9':'9'}"
                                         }  
                                     ],
                                    height : "20px"
                                });
                            }
                        }
                    });

        });

这是实际将数据输入数据库并将其输出到数据表的方法。

String physician = request.getParameter("physician");
    String physicianname = request.getParameter("physicianname");
    String datestart = request.getParameter("datestart");
    String dateend = request.getParameter("dateend");
    String team = request.getParameter("team");
    boolean addSuccess = true;

    PhysicianTeamData physicianTeamData = new PhysicianTeamData();

    String sql = "INSERT INTO " + TABLE_NAME + " " +
            "(team_attendingPhysician, team_physicianName, team_dateStart, " + 
            "team_dateEnd, team_teamNumber) VALUES (?,?,?,?,?);";
    int returnId = 0;
    try {

        dateStart = dateFormat.parse(datestart);
        dateEnd = dateFormat.parse(dateend);

        sqlDateStart = new java.sql.Date(dateStart.getTime());
        sqlDateEnd = new java.sql.Date(dateEnd.getTime());

        ps = con.prepareStatement(sql);

        ps.setInt(1, Integer.parseInt(physician));
        ps.setString(2, physicianname);
        ps.setDate(3, sqlDateStart);
        ps.setDate(4, sqlDateEnd);
        ps.setString(5, team);

        returnId = ps.executeUpdate();

    } catch (Exception e) {
        e.printStackTrace();
        addSuccess = false;
    }

    PrintWriter out = response.getWriter();

    if(addSuccess) {

        PhysicianTeam pt = new PhysicianTeam();
        pt.setRecordNumber(returnId);
        pt.setAttendingPhysician(Integer.parseInt(physician));
        pt.setPhysicianName(physicianname);
        pt.setDateStart(datestart.toString());
        pt.setdateEnd(dateend.toString());
        pt.setTeamNumber(Integer.parseInt(team));

        physicianTeamData.addPhysicianTeamData(pt);

        //out.print(returnId);
        out.print(pt);

    } else {
        out.write("Row Add Failed!");
    }

PhysicianTeamData只是一个arraylist,这些是PhysicianTeam类中的字段:

private int attendingPhysician;
private String physicianName;
private String dateStart;
private String dateEnd;
private int teamNumber;

就像我提到的那样,JSON对象将dateStart作为参数'2',将dateEnd作为参数'3',即使我将它们作为String输出,它们都会抛出错误。

我哪里错了?

0 个答案:

没有答案