【发布时间】:2012-05-29 15:21:40
【问题描述】:
点击下面的这一行时,我发现 sql 命令没有正确结束。
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
String updateQ = "update ANI_999 set First_Name = '"+d.getName()+"', HouseNo = '"+d.getAddr1()+"', Indicator_Sourcefile_iCARE3 = Indicator_Sourcefile_iCARE2, Indicator_Sourcefile_iCARE2 = Indicator_Sourcefile_iCARE1, Indicator_Sourcefile_iCARE1='"+currentFile+"' where CALLER_ID = '"+msisdn+"' ";
int result = stmt.executeUpdate(updateQ);
conn.commit();
conn.close();`
我不断收到 ORA-00933:SQL 命令未正确结束。
这是updateQ 语句的样子:
update ANI_999 set First_Name = 'ZAHARAH BINTI ABDUL RAHMAN', HouseNo = 'No. JKR6357,', Indicator_Sourcefile_iCARE3 = Indicator_Sourcefile_iCARE2, Indicator_Sourcefile_iCARE2 = Indicator_Sourcefile_iCARE1, Indicator_Sourcefile_iCARE1='ICAREP_ANI_SVCPROF_20120402_002.DAT' where CALLER_ID = '058011726'
这里是完整的功能:- 请参考这个符号“
public void updateRecord(icData d, String msisdn) {
Connection conn = null;
Statement stmt = null;
int recCtr = 0;
try {
conn = ds.getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
String updateQ = "update ANI_999 set First_Name = '"+d.getName()+"', HouseNo = '"+d.getAddr1()+"', Indicator_Sourcefile_iCARE3 = Indicator_Sourcefile_iCARE2, Indicator_Sourcefile_iCARE2 = Indicator_Sourcefile_iCARE1, Indicator_Sourcefile_iCARE1='"+currentFile+"' where CALLER_ID = '"+msisdn+"' ";
int result = stmt.executeUpdate(updateQ);
conn.commit();
conn.close();
}
catch(SQLException ex) {
logger.error("iCARE:Error : " + ex.getMessage()); <<this line show me that error>>
}
finally {
try {if (stmt != null) stmt.close();} catch (SQLException e) {}
try {if (conn != null) conn.close();} catch (SQLException e) {}
}
}
【问题讨论】:
-
您是否尝试过打印 sql 并在 SQL 提示符下运行。如果缺少引号,很容易找到。
-
currentFile 中的值是多少。这可能包含一些导致问题的斜线
-
对不起,打印 sql 是什么意思?..我已经检查了“结果”值,它显示数字,表示 sql 工作正常但我不知道为什么我不断收到此错误。ORA-00933: SQL 命令未正确结束。
-
如果您构建更新查询的任何变量包含单引号,则会导致此错误。更严重的是,这种直接从用户输入构建语句的技术容易受到“SQL 注入”(Google it)的攻击,并且是一个永远不应出现在生产代码中的巨大安全漏洞。
-
@SitiHaslinaMohdZulkafli - 嗯。不仅是错误消息,还有 statcktrace。检查我的回答,如果有帮助的话。