| Author |
to find the datatype of given string in runtime
|
Shobana Sukumar
Greenhorn
Joined: Nov 24, 2005
Posts: 17
|
|
|
im getting data from user at runtime.wat method shalli use to find its datatype?
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12911
|
|
|
Where and how are you getting the data? In what format is the data? Is it in a file, or a database, or something else? Please provide more details, otherwise it will be hard to give you a good answer.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Shobana Sukumar
Greenhorn
Joined: Nov 24, 2005
Posts: 17
|
|
|
im getting the data as a string for instance(it can be anything int or date etc). i need to compare the datatype of this to the data type of a column in the database....
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
Maybe find the datatype in the database through metadata and then try to convert the user input to that type and see what happens. You'll get an exception on that Integer if the user entered invalid data.
|
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
|
 |
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
|
|
I think a common convention in this type of situation is to define what the "data type" is. That is you get each field one at a time in a pre-defined order. Then you can use the various tools available to convert it into the internal representation you wish to use. For example, when you expect an int, you can use Integer.valueOf(); when you expect a date, you can use DateFormat or SimpleDateFormat. Each of these APIs will throw an exception or return a value that indicates an ill-formatted String. You can then use this error condition to give a message to the user and possible ask for the input again. HTH Layne
|
Java API Documentation
The Java Tutorial
|
 |
 |
|
|
subject: to find the datatype of given string in runtime
|
|
|