• Post Reply Bookmark Topic Watch Topic
  • New Topic

re: help appreciated

 
joew weakers
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any ideas on how to fix this. The problem is that I need to execute the SQL statement at runtime and the setFillColor method needs a color as an argument. The result of the query is a specific color, e.g. blue. I am getting the following error when I compile the code below:
cannot cast java.lang.String to java.awt.Color

Connection cont = new Connection()
Statement stmt = cont.conn.createStatement();
String query = "Select layer_color, layer_size from user_layers where user_id in \n" + "(select user_id from map_users where user_name = 'Frank Bunce') \n" + "and layer_id in (select layer_id from map_layers where layer_name = 'Cities')";
OracleResultSet ors = (OracleResultSet) stmt.executeQuery(query);
while(ors.next())
{
String dbresult = ors.getString(1);
Color color = (Color) dbresult; //error results from this line
ompoint.setFillColor(color);
}
graphics.add(ompoint);
Cheers Joe
 
Brian Pipa
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

<hr></blockquote>
The problem is you are trying to cast a String (dbresult) into a Color. Strings are not Colors, despite the fact that some strings represent colors.
One way to do what you want is to call a method to do the color conversion for you. Something like:

And the

method could have any number of ways of doing the conversion from a String to a Color. You ned a mapping between Strings and Colors. I'll leave the actual conversion up to you.
Brian
[ October 09, 2003: Message edited by: Brian Pipa ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!