Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

Oracle Sql statement in java

Hey I am trying to run a java program in a Oracle sql load.sql file. Whilerunning the program I am getting the error "ORA-00904: "C"."STAFFID": invalid identifier". I think the issue is in where I prepare the sql statement and trying to execute it. I am trying to get information out from two sql tables: a2_loan and a2_customer. In a2_loan i want to get the loan_num and the contract_date, while in the table a2_customer I want the name and the ird_num. My statement is currently:

String sql = "select a.name, ird_num, loan_num, contract_date from a2_loan, customer b, customer c where aname=b.ird_num and b name=c.name";
PreparedStatement stmt = con.prepareStatement(sql);

I think it is in here that the problem lies but if it is somewhere else please tell me and I will copy the rest of my code!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Note: This answer applied to original question.

SQL statement with annotations:

select a.name           -- 'a' is undefined
     , ird_num          -- note: always qualify (helps others read it)
     , loan_num         --   same
     , contract_date    --   same
  from a2_loan          -- is this support to have alias 'a'?
     , customer b       -- not table `a2_customer`
     , customer c       -- not table `a2_customer`
 where aname=b.ird_num  -- missing period(?), and 'a' is undefined
   and b name=c.name    -- missing period

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...