This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I am storing a flag in the database as type char, but it is set from a web page request object as a string. I need to convert it from type String to char in java. I tried String.charAt(0) which seems to convert to a char type untill I assign it to a variable of type char: char processed = processed_string.charAt(0); when I execute this I get the error message: type undefined.
Any ideas what I am doing wrong? Thanks in advance,
I am sure there is an easier way to do this. However, I just wrote something that went from a String to char sequence. Pretty easy to get a char from the sequence if you know what the position will be:
CharSequence inputStr = "1"; char number = inputStr.charAt(0);
Phil--you are basically doing the right thing by calling charAt. There must be some other reason for the error message. Maybe you can post a bit more of the code or even a small program that shows the problem?
This works for me.It prints "a" as I would expect. You must have something else wrong in your code. Hope that helps.
IBM 286, SCJP, SCWCD, EIEIO
Joined: Nov 17, 2004
I pull the object from the database as follows: (String) result1.getObject(9)--> "F"; next, I pull the char at  from the string: char processed_string.charAt(0) --> 'F' 70 Now, when I assign that result to a char variable it crashes char processed = processed_string.charAt(0) --> undefined
Is the 70 confusing things. What does it mean? Phil
Joined: Dec 17, 2002
Assuming result1 is a ResultSet, you might want to do a result1.getString. Hope that helps.