File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes char - getString() ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "char - getString() ?" Watch "char - getString() ?" New topic

char - getString() ?

kelvin cheung
Ranch Hand

Joined: Mar 27, 2004
Posts: 120

i try to get a char type from a table.
but i get : incopatible types
and i am sure that the colum is of the type char in the table.

whats wrong here?
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
You are trying to store "Object" type to "primitive" type. This will not work. Assign the getString() to another String object. That must solve your problem.
Chris Staten
Ranch Hand

Joined: Sep 24, 2004
Posts: 101
Is this because the rs is an array and therefore the pointer in the array is of type object?

If so I think you can cast the object that you get from the array back into the actual type you want (in this case a char).
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33129

Databases use char(x) and varchar(x) to represent strings. You need to use the getString() method as you are doing. If you happen to know your database field is only one character, you can use getString().charAt(0) to get the character.

rs isn't really an array. It is an object of some type of list. (I'm not sure if that type is array, but I'm thinking it's not.) The resultset getXXX methods give you a more useful data type. For example, you could get a String, Date, int, ... You can get an int primitive back, but not a char primitive.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Chris Staten
Ranch Hand

Joined: Sep 24, 2004
Posts: 101
Gotcha, thanks Jeanne
I agree. Here's the link:
subject: char - getString() ?
It's not a secret anymore!