Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes char - getString() ? 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 "char - getString() ?" Watch "char - getString() ?" New topic
Author

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30076
    
149

Kelvin,
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.

Chris,
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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, 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: http://aspose.com/file-tools
 
subject: char - getString() ?
 
Similar Threads
How to convert set to char[]?
registerOutParameter for table?
String to char problems
Store char[] as column type
getting ascii char from int only seems to work if int is less than 127