This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Data Type Mappings

 
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much Milind.This is precisely the info I wanted.
Herbert
 
I hired a bunch of ninjas. The fridge is empty, but I can't find them to tell them the mission.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic