This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Simple Java DB where clause question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Simple Java DB where clause question" Watch "Simple Java DB where clause question" New topic
Author

Simple Java DB where clause question

Joe Brigs
Ranch Hand

Joined: Jun 06, 2011
Posts: 59



I'm reading two tables the 1st one brings back a field mstr_APPL_CD that I want to use as a lookup to the 2nd query , what am I doing wrong to the 2nd where clause. I know this is very simple, but I'm having my problems. Thanks

I know this may be a JDBC question, but its pretty simple. So I posted it here
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32708
    
    4
You appear to be setting a mstr_APPL_CD String in the Java™ code, and then using a mstr_APPL_CD variable in the SQL. Those two will of course be different.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

1) try to prevent using SELECT *. That will retrieve all columns of the record. Select only what you need; in this case that would be "SELECT APPL_CD FROM ..."

2) APPL_CD is a string, so you should enclose it in quotes.

3) you now have mstr_APPL_CD as a literal inside the statement. You need to replace that with the value of the Java variable; String concatenation should do the trick.

4) I don't think you'll be able to use the Statement after closing it. I'm absolutely sure you can't after closing its connection. Only close these when you're done with them.

5) you should be careful for SQL injection (look it up). Make sure that the APPL_CD column cannot contain any dangerous values. Otherwise use PreparedStatement instead of Statement.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Simple Java DB where clause question
 
Similar Threads
Not able to retrieve values from MySQL(using simple UI)
Help me get started
Help with SQL syntax.
Please give me suggestion
Java Prepared Statement execution not returning any data