wood burning stoves 2.0*
The moose likes JDBC and the fly likes Get Column Type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Get Column Type" Watch "Get Column Type" New topic
Author

Get Column Type

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi:
I'm having problems geting the columnType DATE, this is the code I used for my program, rsmd is ResulSetMetaDeta
switch( rsmd.getColumnType( i ) )
{
case Types.INTEGER:
currentVector.addElement( local + String.valueOf(rs.getInt(i)));
break;
case Types.DECIMAL:
currentVector.addElement( local + String.valueOf(rs.getInt(i)));
break;
case Types.FLOAT:
currentVector.addElement( local + two.format(rs.getFloat(i)));
break;
case Types.DOUBLE:
currentVector.addElement( local + two.format(rs.getDouble(i)));
break;
case Types.NUMERIC:
currentVector.addElement( local + two.format(rs.getDouble(i)));
break;
case Types.CHAR:
currentVector.addElement( local + rs.getString(i));
break;
case Types.VARCHAR:
currentVector.addElement( local + rs.getString(i));
break;
case Types.LONGVARCHAR:
currentVector.addElement( local + rs.getString(i));
break;
case Types.DATE:
StringTokenizer tokens = new StringTokenizer( rs.getDate ( i ).toString(), "-" );
String year = "/" + tokens.nextToken();
currentVector.addElement( local + tokens.nextToken()
+ "/" + tokens.nextToken() + year );
break;
case Types.TIME:
currentVector.addElement( local + rs.getTime( i ) );
break;
default:
System.out.println( "The type was:: " + rsmd.getColumnTypeName( i ) + rsmd.getColumnName( i ) );
currentVector.addElement( local + defaultString );
}
thanks
yoel stern
------------------
Sun Certified Programmer for JAVA 2 Platform
jenkinstechnology llc
Greenhorn

Joined: Aug 18, 2001
Posts: 7
what do you have defined in the database as the datatype? for example, on Microsoft SQL Server, a datetime maps to Types.TIMESTAMP, not Types.DATE like you'd think.
not sure if this helps, but I saw you didn't have Types.TIMESTAMP in your case statement.
paul
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thank You Paul:
You did help me I'm using MS Access because you gave me an idea that in some databases there is diffrent kinds of Type DATE.
I dont know about TIMESTAMP (since I'm using Access) but I see that I didn't use one Type DATETIME now its working exclent I got my column type thru method getColumnTypeName().
I wish you luck
Yoel
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Get Column Type