Conversion int to Integer

I want to retrieve the data of a ResultSet by rs.getInt(3), but I need to convert this data to an Integer, because my PrimaryKey is in Integer format. How could I retrieve an Integer?

Integer MyInteger = new Integer(rs.getInt(3));
I want to retrieve the data of a ResultSet by
rs.getInt(3), but I need to convert this data to an
Integer, because my PrimaryKey is in Integer format.
How could I retrieve an Integer?

Similar Messages

  • Unsigned int to integer conversion

    Hi,
    I have an unsigned integer column in my database table. If I try to retreive the value of the column using resultset.getInt() I'm getting "Numeric value overflow" error as it exceeds the INT_MAX value.
    For eg., if the column value : 4294967295, the expected value from resultset.getInt() is -1 or Numeric Value Overflow error ?
    Is it valid to retrieve the value using getInt() or should I use getLong()?.
    Kindly Clarify.
    Thanks,
    Radhika.

    use getLong

  • Converting int[] to Integer[]

    How to convert an int array to Integer[] without iterating the int[]?
    we can traverse the int[] and add to Integer[]. But the traversing takes too much time. Is there any method to do the above conversion?

    If you are using 1.5, you can use the individual elements of the int[] as if they were an Integer, so why do you need to convert it? If it is to pass the array as an argument, then sorry, you are going to have to traverse the arrays and set the elements. And, at most, this will take a second or two of time (even if you have an array of nearly max size), so in what way is this "taking too much time"?
    Edit: And any API method to do this with a single line of code, would still, inside the method, need to traverse the arrays, so now time would be saved. If it is to save programming time, then take a few minutes to write a method for it now, and then every time you need it in the future, just use that method.

  • Conversion int - binary

    Hello everybody,
    i want to change an integer signed value (on 32 bits) in binary format and do the reverse operation.
    So i wrote :
    String binIntStr = Integer.toBinaryString(-1610612462);
    System.out.println("Binary : "+binIntStr);
    System.out.println("Int : "+Integer.parseInt(binIntStr, 2));The conversion of the int to binary runs correctly, but the reverse operation (binary string to int) throws an NumberFormatException.
    I don't understand why the operation is well done in one way and is not allowed in the other.
    The integer value is in good format (-2147483648 < -1610612462 < 2147483647) so why can't I change the binary string returned by the method toBinaryString in an integer ?

    Integer.toBinaryString() returns a string representation of the integer argument as an unsigned integer in base 2
    from the API doc
    toBinaryString
    public static String toBinaryString(int i)Returns a string representation of the integer argument as an unsigned integer in base 2.
    The unsigned integer value is the argument plus 232 if the argument is negative; otherwise it is equal to the argument.
    This value is converted to a string of ASCII digits in binary (base 2) with no extra leading 0s. If the unsigned magnitude is zero, it is represented by a single zero character '0' ('\u0030');
    otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The characters '0' ('\u0030') and '1' ('\u0031') are used as binary digits.
    Parameters:
    i - an integer to be converted to a string.
    Returns:
    the string representation of the unsigned integer value represented by the argument in binary (base 2).so you will have to figure out out to deal with signed values yourself
    Message was edited by:
    SomeoneElse

  • Int to Integer

    how to convert int value to Integer value?
    Thanks.

    running the risk of sounding stupid
    what's the difference?Sir,
    An int is a primitive. An Integer is an object. Specifically a wrapper object for the primitive type int.
    Java has both objects and primitives.
    Sincerely,
    Slappy

  • Int or Integer

    Having a problem with my entity bean.......... I have set my primary key type to type java.lang.Integer.... my ejbCreate is returning an Integer but when i try to compile is says that type int is required. i cannot change it to an int as the primary key has to be an object and it will not deploy. Why is it asking for an int? what is asking the the ejbCreate for an int? any help!

    Hi,
    If you are doing an insert within your create you should have something like this...
    pstmt.setInt(1,ID.intValue() );Where pstmt is the PreparedStatement for the insert! Send ur code so I can understand what your trying to do.
    Hope it helps

  • String.valueOf(int i)  /   Integer.toString()

    What's the difference between these methods? They seem to both do the same thing... convert an int into a string

    No, they don't
    static String valueOf(int i)
              Returns the string representation of the int argument.
    String toString()
              Returns a String object representing this Integer's value. Perhaps you intended to compare the String.valueOf to this?
    static String toString(int i)
              Returns a String object representing the specified integer. If so, then yes, they do the same thing.

  • Int and Integer

    whats the difference between these two anyway..?

    int is a primitive type and Integer is a class. You would generally use primitive types wherever possible because they are much more efficient. You would use classes, for instance, if you have to put your values into a collection such as an ArrayList.

  • Fundamental Question about int vs Integer

    I don't really understand what the difference is between using the "int" keyword and using the Integer type. I've come to realise that "int" cannot be null whereas Integer can be null but why isn't int just an Integer type? Like an alias of sorts. I realise this a fairly basic question but I'm sure I'm not the only one pondering this :)

    I'm not sure if the autoboxing stuff in 1.5 affects
    this at all or not, but one key difference between
    objects and primitives is that primitives get passed
    by value, whereas objects are passed by reference.
    NOOOOOOOOOOOOOO!
    Wrong. Wrong. Wrong. Wrong. Wrong.
    Everything in Java is passed "by value". Everything.
    Pass-by-value
    - When an argument is passed to a function, the invoked function gets a copy of the original value.
    - The local variable inside the method declaration is not connected to the caller's argument; any changes made to the values of the local variables inside the body of the method will have no effect on the values of the arguments in the method call.
    - If the copied value in the local variable happens to be a reference (or "pointer") to an object, the variable can be used to modify the object to which the reference points.
    Some people will say incorrectly that objects are passed "by reference." In programming language design, the term pass by reference properly means that when an argument is passed to a function, the invoked function gets a reference to the original value, not a copy of its value. If the function modifies its parameter, the value in the calling code will be changed because the argument and parameter use the same slot in memory.... The Java programming language does not pass objects by reference; it passes object references by value. Because two copies of the same reference refer to the same actual object, changes made through one reference variable are visible through the other. There is exactly one parameter passing mode -- pass by value -- and that helps keep things simple.
    -- James Gosling, et al., The Java Programming Language, 4th Edition

  • Concatenating int to int

    Greetings,
    Is there another way that I can concatenate int to int. For eg,
    I have int i = 12 and int x = 34 and I would like to get int result = 1234.
    The one way of concatenating int to int is to convert both int to string, append them together and parse those string back to int. Is there any class or something that makes this approach little easier?. I am being very curious.
    I realy appreciate your help. Thank You in Advance.
    Regards,
    Pinal.

    Use Strings and conversions.
    int newInt = Integer.parseInt(
    (String)(String.valueOf(firstInt) +
    String.valueOf(secondInt)) );this is the very thing they are trying NOT to do...
    <sarcasm>
    i take it you read the entire thread?
    </sarcasm>

  • Output problem urgent!!

    Okay so heres the problem i have a piece of code to convert a decimal value that a user enters into a binary value. My algorithm works its just when the binary value is displayed only the last element of the binary value to be outputed is displayed. But i want all the values of the binary number to be displayed. I dont know what to do plz help.
    the code i am using is:
    import java.awt.*;
    import java.awt.event.*;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import javax.swing.*;
    public class conversion extends JPanel implements ActionListener
         JPanel board;                // Panel for buttons
         JLabel canvas;               // Text Area for displaying answer
        JButton convert, reset;  // buttons
           JTextField input;       //input text box
             public conversion()
                 super(true); // Call constructor of parent
              // Standard layout (flow)
                 setLayout(new FlowLayout());
              // Set up two panels, control board and canvas
                 board = new JPanel(true);
              canvas = new JLabel();
                 board.setPreferredSize(new Dimension(100, 100));
                 canvas.setPreferredSize(new Dimension(300, 300));
              board.setBorder(BorderFactory.createLineBorder(Color.black));
              canvas.setBorder(BorderFactory.createLineBorder(Color.blue));
              // Create buttons and attach listeners
                 convert = new JButton("Convert");
                 convert.addActionListener(this);
                 reset = new JButton("Reset");
                 reset.addActionListener(this);
              input = new JTextField(8);
                 add(canvas); add(board);
              // Add button to board panel
            board.add(convert);
              board.add(input);
              board.add(reset);
         public void actionPerformed(ActionEvent e)
              String inputInfo;
              inputInfo = input.getText();
              if (e.getSource() == convert){           //action on convert button
               //algorithm for decimal to binary conversion
              int a = Integer.parseInt(inputInfo);    //Gets decimal number inputed
              if (a > 255){
                   canvas.setText("Please enter a number below 256");
              else {
              int b[] = new int[50];
              int i = 0;
              if (a / 2!=0 || a==1)               //Checks to see if decimal number is divisible by 2
              {                                             //Or exactly equal to 1
              while(a!= 1)                            //While loop for when the decimal inputted is not equal to 1
              b= a % 2;                              
              a = a / 2;                                   //Check to see if the remainder is divisible by 2
              i++;
              b[i]= 1;
              for(int x=i;x>=0;x--)
                                                      //Displays the binary answer
                   int answer = b[x];
                   String stringAns = Integer.toString(b[x]);     
                   System.out.println(stringAns);
                   canvas.setText ("The binary for your decimal is: " + stringAns); // this is the problem here, only the last element is displayed
              if (e.getSource() == reset){           //action on reset button
                   canvas.setText("");     
                   input.setText("");
              //Graphics g = canvas.getGraphics();}
         public static void main(String[] args)
         // Create a Blob entity
         conversion b = new conversion();
              // Set up outer frame, and its exit behaviour
         JFrame frame = new JFrame("Decimal to binary");
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // Set the main content frame to be the Blob,
              // size the frame (pack) and make it visible
         frame.setContentPane(b);
         frame.pack();
         frame.setVisible(true);

    pauze wrote:
              for(int x=i;x>=0;x--)
                                                      //Displays the binary answer
                   int answer = b[x];
                   String stringAns = Integer.toString(b[x]);     
                   System.out.println(stringAns);
                   canvas.setText ("The binary for your decimal is: " + stringAns);        // this is the problem here, only the last element is displayed
    Each element in the array b contains one digit of the binary representation. You need to convert each digit into a character and then concatenate all the characters into a String before displaying anything.

  • How to convert an Integer to int

    Integer y = new Integer(1);
    int x = ????(y);
    What is the missing command to do the above conversion ?
    I've tried casting etc.
    It's mid nite and I'm still at work!
    Appreciate all help. Thanks!

    Integer is an Object. int is a primitive base type. to convert an Integer Object into an int:
    //let's say you read a line from a file, and the line is this
    5
    //normally, since files contain characters, you would call a method that reads in String Objects
    //so the 5 is actually a String, which you need to convert to an int to use for math, calculations,
    //expressions, etc.
    String blah = Keyboard.readLine();
    int x = Integer.parseInt(blah);
    // now x equals the int 5.
    hope this helps.

  • Conversion of String to Int

    Had some trouble with passing a string input via the command screen and changing it to an int. Im prob using the wrong code but im not sure if that is it.
    import javax.swing.JFrame;
    import java.util.Scanner;
    public class P524Driver
    public static void main ( String args[] )
         Scanner input = new Scanner(System.in);
         // Input the rows of the Diamond
         System.out.print ("Input the number of rows (Must be and oddnumber): ");
    int x = input.nextInt();
         String z;
         if (x > 0) //     Determine if the value entered was valid
         while ( x % 2 == 0 )
              System.out.print( "You Input a even number try again: ");
              x = input.nextInt();
              while ( x % 2 != 0)
              System.out.print( "Input the charater: ");
              z = input.next();
              int y = Integer.parseInt(z);
    {else{ System.exit(0);}
    }

    Ok I don't know if this is going to work with your input, but here goes. The way I declared user input was as so : BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); and the way I declared the integer value of the input was as so : int value = Integer.parseInt(console.readLine());Hope this helps!

  • Conversion from String to int..NumberFormatException??

    Hey all
    I am trying to read in a file that has nothing but numbers listed one per line. I am using the bufferedReader class and reading in by line. When I check to see if the one 'string' is the same as another, it says they are the same, when really they are different. I then thought to convert the numbers to integers after reading them in, but it gives me a number format exception. My process is simple:
    1) line = in.readLine();
    2) int variable = Integer.valueOf(line).intValue();
    This gives me the damn exception. The numbers are three digits, e.g. 333, etc. Does anybody know how I can avert this problem or achieve the result I am looking for another way? All I want is to know what numbers are listed in their, without going through by hand checking. Thanks

    hi...try this..
    1.Use filereader instead of bufferedreader..OKAY
    2. OR USE...
    String str = br.readLine();
    use... int sanjeev = Integer.parseInt(str);
    3 OR...and helloooo one thing more...how u r checking that these 2 strings r same..
    get CLEAR IDEA about equals method and "=="..

  • Conversion of object into integer

    hi
    How to convert Object into integer.
    I want to get value of JTable cell.So im doing
    for(int i=0;i<4i++)
    String value=(String) JTable.getValueAt(i,2);
    s.o.p("Table value :"+JTable.getValueAt(i,2));
    int changedValue=Integer.parseInt(Value);
    s.o.p("Changed value :"+value);
    }JTable.getValueAt(0,2) : 0
    JTable.getValueAt(1,2) : 0
    JTable.getValueAt(2,2) : 2
    JTable.getValueAt(3,2) : 4
    Theses are the respective values of the respective row positions
    Im able to get values of 1st row and 2nd row which are of 0 values
    But the value of third row and 4th row im gettin an exception
    java.lang.Integer cannot cast to java.lang.String
    please help anyone

    If the data in the model is of type Integer you can't cast it to String.
    You need to cast this to Integer and call intValue method to get as int.
    If you want further help post a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html] that demonstrates the problem.

Maybe you are looking for

  • How to do a FTP from one system to another

    Hi, I have a program which creates a file from the master data in one system (Logistics), and I have another program in   another system (HR) which writes the contents from this file to a custom table. I want to the avoid manual movement of the file

  • How to find out Query last used by whom

    Dear All, Can any one tell me that "How to find out the Query last used by whom. I have already searched in SDN but no luck. In my system BW Stats are not installed and I have already checked the below tables. RSZELTDIR  - Directory of the reporting

  • ALV edit mode

    Hi All, I am displaying an ALV List.There is a column called Final invoice indicator which is a check box.When the user checks this check box that record in the ALV output has to be changed to non-editable mode.I am using classes for ALV display.How

  • SOMEBODY PLEASE HELP ME, CAN'T TRANSFER VIDEOS FROM IPOD

    Okay, so, my english assignment is due in like 10 hours, and I CAN'T TRANSFER THE VIDEO FROM MY IPOD TOUCH TO THE COMPUTER. I'VE BEEN DREADING THIS. I recorded my english assignment via my iPod Touch because it has HD Video Recording. The video size

  • Deleted time machine backups 3 times

    this is my 3rd time i had to delete it because it kept giving me it cannot find a backup disk whatso ever i got it to finally work some how and now it's backing up everything once again but i'm affarid once it starts to acually do its inital first ba