Results 1 to 5 of 5
  1. #1
    Basit56 is offline Member
    Join Date
    Aug 2009
    Posts
    48
    Rep Power
    0

    Default How to check String confirmation with integer

    Hi,
    Hope you all will be fine.I want to ask suppose i am getting values from a column of a database and the returning values are all integer but some values in the same column are String . So i want to put a check that if string is encounter instead of int then convert it to int and print them.
    Like i have a code that get int like this.The code is in a loop so it's continue to running as long as it gets all the values

    Java Code:
    int mailbox = voice.mailbox;
    what i want to do is
    Java Code:
    if(mailbox is string){
        convert mailbox to Int;
        print mailbox;
    }else{
        print mailbox;
    Conversion is very simple from string to int i am having problem at how can i put this check

    if(mailbox is string)
    how can i do it.

    Thank you

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Always convert and catch the NumberFormatException that results if the value is not an integer.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,185
    Rep Power
    20

    Default

    Eh?
    If the column in the db is a string (varchar or whatever) then you should be reading it out as a string (getString()).

    Database columns do not consist of different data types, so what you're actually saying is that you have a column which is varchar2 (to use Oracle), but that contains numbers (shoot the designer).

    ETA: In fact, since you're printing it out, why bother converting?

  4. #4
    jogep is offline Member
    Join Date
    Dec 2009
    Location
    Germany
    Posts
    43
    Rep Power
    0

    Default

    One way is to use the StringUtils Class from the apache Commons Lang Project.

    Java Code:
    if(StringUtils.isNumeric(myIntString))
    {
     //parseInt
    }

  5. #5
    Basit56 is offline Member
    Join Date
    Aug 2009
    Posts
    48
    Rep Power
    0

    Smile

    Hi Toll,
    :) You compel me to smile (shoot the designer) wow great. But yes that the case my database(sorry not mine but on which i am to working now) column has a datatype of varchar2 and contains number also. Anyways :).
    Now i am to getting string from there whether is a number or name.

    Thanks for make me smile :) cheers ;)

Similar Threads

  1. String to Integer Conversion in JSP
    By vinikz in forum New To Java
    Replies: 8
    Last Post: 11-10-2010, 03:45 PM
  2. how to convert a string to an integer
    By LAW in forum New To Java
    Replies: 6
    Last Post: 11-09-2009, 04:29 AM
  3. check if String is an integer?
    By McChill in forum New To Java
    Replies: 5
    Last Post: 05-02-2009, 08:51 PM
  4. Integer to String
    By zervine in forum Forum Lobby
    Replies: 3
    Last Post: 09-12-2008, 01:07 PM
  5. String to Integer conversion
    By eva in forum New To Java
    Replies: 2
    Last Post: 12-17-2007, 04:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •