Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Data Type Mappings

 
Herbert Maosa
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
I have a problem mapping database types to corresponding sql types such that I can not successfully execute queries.I am using a database whose type I dont know(I dont whether it is a Microsoft Access,Oracle,Microsoft sql,db2... type), because I got it as a sample database and I am using Sun's jdbc driver to access it. I am able to retrieve table names as well as column names in each table using the metadata interfaces, but I am stuck on getting the data types.Invoking the getColumnType() of the ResultSet interface gives me java.sql.Types which are constants, but I dont know what these constants translate to, so that I can provide the appropriate type in the query.
Is my situation understood ?
Help me out here!
Thanks in advance
Herbert
 
Harish Kashyap
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getColumnType() will return the constant value assigned to the column type. You can translate the value accordingly.
like if it is 0 for integer you can use getInt() method. You can get the list of constants and their values throu reflection or using some tool like IBM VisualAge For Java.
Or else you can explore the sun.jdbc.odbc.JdbcOdbcResultSet class to get the required methods.
 
Milind Kulkarni
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Herbert,
Here is the information you wanted:
package java.sql;
public class Types {
public final static int BIT = -7;
public final final static int TINYINT = -6;
public final static int SMALLINT = 5;
public final static int INTEGER = 4;
public final static int BIGINT = -5;

public final static int FLOAT = 6;
public final static int REAL = 7;
public final static int DOUBLE = 8;

public final static int NUMERIC = 2;
public final static int DECIMAL = 3;
public final static int CHAR = 1;
public final static int VARCHAR = 12;
public final static int LONGVARCHAR = -1;

public final static int DATE = 91;
public final static int TIMESTAMP = 93;
public final static int TIME = 92;

public final static int NULL = 0;
public final static int BLOB = 2004;
public final static int CLOB = 2005;
public final static int ARRAY = 2003;

}
Regards,
Milind

[This message has been edited by Milind Kulkarni (edited July 12, 2000).]
 
Herbert Maosa
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much Milind.This is precisely the info I wanted.
Herbert
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic