getColumnType of ResultSetMetaData returns NUMERIC type for all integer, double types.

My application is running fine with Java 1.5, Oracle JDBC driver 10i with Oracle 10i database.  In this application, there is a part of code which uses getColumnType of ResultSetMetaData function to find out the column type of the particular column. Based on the column type value, that column value is retrieved.
For example If the return value is "Double", resultSet.getDouble(columnName) method is used to retrieve. If it is "Long", then resultSet.getLong(columnName) is used.

Now I want to use the same code to access the database Oracle 8i. When I used the application as it is to access the 8i database, the getColumnType method returned "Numeric" instead of either Double/ Long.
I thought the problem was with JDBC driver jar file. so I replaced Oracle 10i jdbc driver with Oracle 8.1.7.1 driver. But Still I had the same problem. Now I tried replacing Java 1.5 with Java 1.4 too. But still that return type was "Numeric". no luck. Is it the problem with Oracle 8i database?

I almost tried all the combination of Java 1.4/ Java 1.5, Oracle jdbc driver 10i/8i and Oracle database 10i / 8i.  No luck. Please help me to solve this problem.

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Date;
import oracle.jdbc.pool.OracleDataSource;
 
public class DBAccessPool 
{
     
     public static void main(String args[]) throws ClassNotFoundException, SQLException 
     {
			ResultSetMetaData metaData = null;
			String columnName = null;
			int columnType;
			String columnValue = null;
 
			OracleDataSource ds = new OracleDataSource();
			ds.setDriverType("thin");
			ds.setServerName("serverName");
			ds.setPortNumber(1561);
			ds.setDatabaseName("dbName");
			ds.setUser("userName");
			ds.setPassword("password");
          
         
			Connection conn = ds.getConnection();
 
			PreparedStatement stmt = conn.prepareStatement(selectQuery);
           
          
			ResultSet rset = stmt.executeQuery();
			metaData = rset.getMetaData();
			if(rset.next()) {
			   for(int columnCount = 1; columnCount <= metaData.getColumnCount();columnCount++)
			   {
				   columnValue = null;
				   columnName = metaData.getColumnName(columnCount);
				   columnType = metaData.getColumnType(columnCount);
				   
				   if(columnType == Types.CHAR || columnType == Types.VARCHAR || columnType == Types.LONGVARCHAR)
				   {
					   columnValue = rset.getString(columnName);
				   }
				   else if(columnType == Types.INTEGER || columnType == Types.BIGINT || columnType == Types.SMALLINT || columnType == Types.NUMERIC)
				   {
					   long templong = rset.getLong(columnName);
					   if(!rset.wasNull())
					   {
						   columnValue  = Long.toString(templong);
					   }
				   }
				   else if(columnType == Types.DECIMAL || columnType == Types.DOUBLE || columnType == Types.FLOAT || columnType == Types.REAL)
				   {
					   double tempDouble1 = rset.getDouble(columnName);
					   if(!rset.wasNull())
					   {
						   columnValue  = Double.toString(tempDouble1);
					   }
				   }
				   else if(columnType == Types.TIME || columnType == Types.TIMESTAMP || columnType == Types.DATE)
				   {
					   Timestamp sqlTimeStamp = rset.getTimestamp(columnName);
					   if(!rset.wasNull())
					   {
						   columnValue = sqlTimeStamp.toString();
					   }
				   }
				   System.out.println("Column Name: "+columnName+ " Column Type: "+columnType + "  Column Value: "+columnValue + " "+metaData.getColumnClassName(columnCount));
			   }
			   
			   }
			rset.close();
			stmt.close();
			conn.close();
  }

Open in new window

makeshkumar_rAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
What does it matter - your code is only turning it into a String anyway? You could probably call getString or at least getObject(n).toString
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
makeshkumar_rAuthor Commented:
Thank you. That's a good catch. I was trying too hard to find out how to get the right value for getColumnType() method. I didn't think of other ways.
0
CEHJCommented:
If you want to be more type-specific:



case Types.NUMERIC:
	Number n = (Number)rs.getObject(x);
	float f = n.floatValue();
	double d = n.doubleValue();
	// And so on for all other numeric primitives

Open in new window

0
jlkukaCommented:
The solution is fake for me. The promisse is clariry way to determine the type of a column and this job is ot complete.

really disappointed
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.