I'm getting an error that says "Syntax error: Encountered "t" at line 1, column 54"
我得到一个错误,它说"语法错误:在第1行,第54栏中遇到"
This only seems to happen when the enhanced for loop for the History list iterates more than once. It works perfectly fine when I add one row of items, but when I add any more it gives me this error
这似乎只有在对历史列表的循环进行多次迭代时才会发生。当我添加一行的时候,它的效果非常好,但是当我再添加时,它会给我这个错误。
Here is my code:
这是我的代码:
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 个解决方案
#1
1
You've probably got an SQL injection problem, and the t
mentioned in your error is coming from something like
您可能已经遇到了SQL注入问题,您的错误中提到的t来自于类似的东西。
INSERT INTO .....'Can't Tolerate X'
^---
#1
1
You've probably got an SQL injection problem, and the t
mentioned in your error is coming from something like
您可能已经遇到了SQL注入问题,您的错误中提到的t来自于类似的东西。
INSERT INTO .....'Can't Tolerate X'
^---