获取" SQL命令未正确结束"错误

时间:2016-05-18 07:17:16

标签: java oracle sqlexception

为什么我在eclipse中运行此查询时遇到错误?

java.sql.SQLException: ORA-00933: SQL command not properly ended

代码:

String policy = "select p.policy_id,i.insurance_type,c.reason,i.insured_amount,i.max_claim_amount,c.claim_status from claim as c join policy as p on c.policy_id=p.policy_id join insurance as i on p.insurance_id=i.insurance_id where c.user_id=?";
PreparedStatement policyst = con.prepareStatement(policy);
policyst.setString(1, userId);
ResultSet policyrs = policyst.executeQuery();

2 个答案:

答案 0 :(得分:3)

Oracle不支持as表别名;你应该删除它们:

SELECT p.policy_id,
       i.insurance_type,
       c.reason,
       i.insured_amount,
       i.max_claim_amount,
       c.claim_status
  FROM claim c
       JOIN policy p ON c.policy_id = p.policy_id
       JOIN insurance i ON p.insurance_id = i.insurance_id
 WHERE c.user_id = ?

答案 1 :(得分:2)

从您的陈述中删除“AS”字样