• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mapping of java.sql.Types

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am parsing XML document and am getting strings for various data types as "java.sql.Types.FLOAT","java.sql.Types.INTEGER", "java.sql.Types.VARCHAR" etc..... I have to compare these strings with java.sql.Types constants. Do I need to create a map of all possible java.sql.Types and do String to integer mapping? Is there better way than creating hashmap of strings to integers. I have this fix but I have to find all possibe java.sql types.
Any better way??

-Mccoy

public static String[] keys = { "java.sql.Types.FLOAT" , "java.sql.Types.INTEGER", "java.sql.Types.VARCHAR" };
public static int[] values = { java.sql.Types.FLOAT,java.sql.Types.INTEGER, java.sql.Types.VARCHAR};

static HashMap theMap = new HashMap();
static {
for (int i = 0; i < values.length ; i++ )
{ theMap.put(keys[i], new Integer(values[i])); }
}
public static int getValue(String token) {
return( ((Integer) theMap.get(token)).intValue() );
}
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could obtain the value through reflection.

@see Class#getField
@see Class#getDeclaredField
@see java.lang.reflect.Field
 
mooooooo ..... tiny ad ....
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic