wood burning stoves 2.0*
The moose likes JDBC and the fly likes compare a long datatype to a string in select statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "compare a long datatype to a string in select statement" Watch "compare a long datatype to a string in select statement" New topic
Author

compare a long datatype to a string in select statement

Srikrishna DhumalRao
Greenhorn

Joined: Oct 05, 2004
Posts: 17
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.


srikrishna
Anandh Ramesh
Ranch Hand

Joined: Dec 15, 2004
Posts: 61
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...


cheers,<br />Anandh
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

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

Joined: Oct 05, 2004
Posts: 17
Thanks,
I got it
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: compare a long datatype to a string in select statement
 
Similar Threads
Unable to define/override @Id(s) on a subclass; which classes i have to solve?
Invalid column type
How to put a tool tip in a displaytag column
JTable width and height
Create constraint