Discussions

Expand all | Collapse all

Select bigint data type value by using jdbc interface

  • 1.  Select bigint data type value by using jdbc interface

    Posted 02-12-2019 13:34

    Hi,

    I created a table STUDENT in which one ID column of data type bigint is present and inserted 2503188345 in table STUDENT.

    If I am executing select query like
    Select id from student;

    Then I am getting 2503188345.

    But If I am executing the above same select query by using jdbc interface to get the id of student, then I am getting value in negative.

    Thanks



  • 2.  RE: Select bigint data type value by using jdbc interface

    Posted 02-12-2019 14:03

    Hi @Ishika -

    Can you provide more context around how you are using jdbc? Either what tool/environment you are in or the code you wrote? That will help us debug what the issue might be rather than guess.

    Best,
    Randy



  • 3.  RE: Select bigint data type value by using jdbc interface

    Posted 02-12-2019 14:51

    Hi @randyzwitch,

    Thanks for the reply.
    By using JDBC interface, like this I am doing

    String sql = “SELECT ID from STUDENT”;
    ResultSet rs = stmt.executeQuery(sql);

        while (rs.next()) {
          String id = rs.getString(1);
          System.out.println("" id is ""+id);
        }
    

    Thanks



  • 4.  RE: Select bigint data type value by using jdbc interface

    Posted 02-13-2019 07:36

    hi @Ishika
    it’s a bug on jdbc driver that uses the getInt method when you ask a text representation of a BigInt field.

    Could you try to change your code to String.valueOf(rs.getLong(1)) ?