This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes java.sql.Type to java type mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.Type to java type mapping" Watch "java.sql.Type to java type mapping" New topic
Author

java.sql.Type to java type mapping

Joshua White
Ranch Hand

Joined: Jun 04, 2001
Posts: 97
My understanding is that this relationship between java.sql.Types and java types is defined in the jdbc spec. Is there a class where I can map a java.sql.Type to a java type? I am looking for a string if at all possible.

ex..
public String getJavaType(int sqlType)

Regards,
Joshua
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
I don't believe that such a thing exists. The best you can do is look at the "java.sql.Types" API to see what's defined there.
One of the difficulties in doing the mapping you propose is that there might not be one--and only one--way to map. For example, if something is "Numeric" in the database, should that to map to an "int", "long", "float", "double", "Integer", "Long", "Float" or "Double" in Java?
I believe that the Java <--> Database type mapping is defined as a matrix of legal possibilities because there is no one-to-one mapping.
[ October 29, 2003: Message edited by: Wayne L Johnson ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30136
    
150

This mapping tends to be database specific. What database are you using?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Joshua White
Ranch Hand

Joined: Jun 04, 2001
Posts: 97
mssql
Have you come across any resources that have mappings for the different databases?
Joshua
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30136
    
150

The mappings for a specific database are usually in the database documentation. I've seen it for db2 and Oracle.
Sun has a generic list that should apply to most databases. The exceptions would be in the database docs.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.sql.Type to java type mapping
 
Similar Threads
How to get the value of a boolean OUT parameter in stored procedure
Error: SQL type is not supported by this driver
PreparedStatement sucks
java sql TYPE
How to handle Enumeration values in java.sql.Types ?!! Is it possible ?!!