• 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

Matching a String with a certain record

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys, I'm a ColdFusion developer and have just started into java.
In ColdFusion if you want to see if a string matched the name of a column value (from a database) you would do this:



How would I check for a value like this in Java?
Here's what I got:



Any ideas?
Thanks guys and take care,

Chris
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
common question. simple answer:

don't use "==", it's checking for something else entirely than what you think it is.

use the ".equals()" method...


if you search around on this site, you're bound to find a more tech. answer. or, wait a while and somebody will post it here (i may myself later when i have more time...)

good luck!!!

 
chris le
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help!
But here's another question along the same lines.
Why does it have to be in a loop to work.

I have tried this:

It doesn't match it because the cursor is still on the last record "John".
Why is this happening even after I user the first() method? I even tried the absolute method.

Any ideas?
Thanks!
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chris,

The JDBC code you're using is at a lower level than ColdFusion tags. It gives you a lot more control over how you interact with the database. Consequently it requires more code to do the simple things. ColdFusion is akin to the tags provided by JSTL or Struts. These technologies do the simpler things very succinctly, further hiding the complexity behind the scenes from the developer. In simple terms a loop is required as your ResultSet returns more than one row.

Your second question is more difficult. Your JDBC driver has given you a ResultSet of ResultSet.TYPE_FORWARD_ONLY, which suggests only JDBC 1.0 support. JDBC 2.0 introduced scrollable ResultSets which support the first() and last() methods, etc. Calling rs.first() on a forward-only ResultSet has no effect, hence the ResultSet still points at the last record found by rs.next().

Hope that helps. As you appear to crave a full understanding of these concepts I suggest you have a good browse through the API documentation for the java.sql package on Sun's website and also study the JDBC 2.0 tutorial there.

Jules
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that the API documentation Julian mentioned is available at
http://java.sun.com/j2se/1.4.2/docs/api/

Sun's JDBC tutorial is available at
http://java.sun.com/docs/books/tutorial/jdbc/index.html

Moving this to the JDBC forum...
[ August 20, 2004: Message edited by: Dirk Schreckmann ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic