Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get Column Type

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic