语法错误:第54行第1行遇到“t”

时间:2013-04-19 17:15:58

标签: database netbeans syntax arraylist

我收到一条错误,上面写着“语法错误:遇到”t“第1行第54栏”

只有当历史记录列表的增强for循环迭代多次时才会出现这种情况。当我添加一行项目时它完全正常,但是当我再添加它时,它会给我这个错误

这是我的代码:

public void databaseSave( ArrayList <Patient> pList )
{

    try
    {
        stmt = getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

        //Statement stmt = con.createStatement();

        //Deletes all records from the Patient Table.
        deleteAllFromPatientTable();

        //Selects all the records from the Patient table.
        selectAllFromPatient();


        System.out.println("Before loop");

        for ( Patient p: pList )
        {

            patientInsertSQL = "Insert Into SHAUN.PATIENT VALUES (" + p.getPatientNum() + ", '"
            + p.getPatientName() + "', '" + p.getPatientAddress() + "', '"
            + p.getPatientPhone() + "')";

            res = stmt.executeUpdate(patientInsertSQL); 

            System.out.println(res);


            ArrayList <History> tempHistList = p.getHistory();

            //Deletes all the records from the history table.
            deleteAllFromHistoryTable();

            //Selects all the records from the history table.
            selectAllFromHistory();

            for ( History h: tempHistList )
            {                   
                historyInsertSQL = "Insert Into SHAUN.HISTORY VALUES (" + h.getHistID() + ", '" + h.getConditionName() + "', '" + h.getMedication() + "', '" + h.getDateOccured() + "', " + p.getPatientNum() + ")";

                res = stmt.executeUpdate(historyInsertSQL); 

                System.out.println(res);

                //Loop Checker
                int i = 1;
                System.out.println("In the History Loop " + i);
                i++;
            }

            System.out.println("In the loop!");

        }

        stmt.close();
        result.close();
        con.commit();

        System.out.println("After Loop and close");

    }
    catch (SQLException err)
    {
        System.out.print(err.getMessage());
    }
}

1 个答案:

答案 0 :(得分:1)

您可能遇到了SQL注入问题,错误中提到的t来自

INSERT INTO .....'Can't Tolerate X'
                     ^---