0

我收到一条错误消息,显示“语法错误:在第 1 行第 54 列遇到“t””

这似乎只发生在历史列表的增强 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());
    }
}
4

1 回答 1

1

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

INSERT INTO .....'Can't Tolerate X'
                     ^---
于 2013-04-19T17:18:34.883 回答