• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Simple Java DB where clause question

 
Ranch Hand
Posts: 70
IBM DB2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
Marshal
Posts: 79174
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Listen. That's my theme music. That's how I know I'm a super hero. That, and this tiny ad told me:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic