Help coderanch get a
new server
by contributing to the fundraiser
  • 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

compare a long datatype to a string in select statement

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need to fetch records from the database(oracle) where long data type column is like a string in a java file.when i tried with column like 'string'it gives amessage " inconsistent datatypes".
can any one throw some light on this.
Thanks in advance.
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

try typecasting the variable to a string and then you can compare them.
eg. String.valueOf(<long variable> will convert it to a string.

if you're not going to perform any computation on this, you can also get the data as a string using rs.getString() where rs is the resultset object.

tell me which one is suitable for you...
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Srikrishna,
The following works for me using JDK 1.4.2, Oracle 9.2.0.4 (on SUN [sparc] Solaris 9) and Oracle's "thin" JDBC driver.

First, I create a database table with a LONG column:

Then I insert some data into that table:

Note that these first two steps are done using SQL*Plus (not java).

Now I write some java code to fetch the data from MY_TABLE:
[Note that this is pseudo-code -- it is uncompiled and untested!]

Hope it helps.

Good Luck,
Avi.
 
Srikrishna DhumalRao
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks,
I got it
 
What's a year in metric? Do you know this metric stuff tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic