Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6383817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:41:52+00:00 2026-05-25T02:41:52+00:00

while(rs.next()){ Object o = rs.getObject(i); System.out.println(o.getClass()); //prints java.lang.Integer } The problem is that I

  • 0
while(rs.next()){
          Object o = rs.getObject(i);
          System.out.println(o.getClass()); //prints java.lang.Integer
}

The problem is that I have a smallint type in the database and the driver returns an Integer type. I am doing some logic at runtime and then trying to insert the value back in the database using the type I was previously handed by the DB.

I would like DB2 to return me a java.lang.Short, but I am not sure if thats possible.

Has anyone encountered this before and what did you do for a workaround?

The basic issue is – I have both int and smallint columns in the DB2 database and I need my java code to figure out which is which based on the result set.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:41:52+00:00Added an answer on May 25, 2026 at 2:41 am

    Instead of relying on the type of the Java object returned, ask the resultset for the actual database type of the column:

    String databaseTypeName = resultSet.getMetadata().getColumnTypeName(columnIndex);
    

    or

    int sqlType = resultSet.getMetadata().getColumnType();
    boolean isSmallInt = (sqlType == Types.SMALLINT);
    

    See http://download.oracle.com/javase/6/docs/api/java/sql/ResultSetMetaData.html. The javadoc is such a valuable source of information!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with the code below. Compiler says incompatible types, java.lang.object[][] required
myRs=myStmt.executeQuery(select i_col,col_name from tab_col) i=0 while (myRs.next()): list= myRs.getString(I_COL)+','+myRs.getString(COL_NAME) i have a jython code
I have a jQuery function that does a .clone() on an object, and then
Iterator it = myHashMap.keySet().iterator(); while (it.hasNext()) { int next = it.next(); } That doesn't
$(.sectionHeader).click(function() { var row = $(this).parent(); while (row.next().length != 0) { row = row.next();
What's the best Python idiom for this C construct? while ((x = next()) !=
While considering the JS framework for my next project, I can see the scale
While working in a Java app, I recently needed to assemble a comma-delimited list
I have only started learning Java. My task is to create a file server
How to add Image in different different HSSFCell object in poi ? I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.