473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Confusion with DatabaseMetadata.getTypeInfo.

dmjpro
2,476 2GB
I am copying from a Database to another Database.
I am generalizing this program.
Actually to reduce the overhead of Data Type mapping between the source Database and target Database.
What I am doing ..... I am getting the Table column info using DatabaseMetadata.getColumns and there I getting the Column type of java.sql.Types.
Now to map these types with the target Database types I am retrieving the SQL types using DatabaseMetadata.getTypeInfo.
Now my confusion is some constant values are missing with a particular Database(here Postgres)
If my Source Database's Column Type matches with a Constant Value which is missing in my Target Database then what should I be doing?
Should I map this manually?
Please Help!

Debasis Jana
Apr 11 '08 #1
8 2359
dmjpro
2,476 2GB
I am copying from a Database to another Database.
I am generalizing this program.
Actually to reduce the overhead of Data Type mapping between the source Database and target Database.
What I am doing ..... I am getting the Table column info using DatabaseMetadata.getColumns and there I getting the Column type of java.sql.Types.
Now to map these types with the target Database types I am retrieving the SQL types using DatabaseMetadata.getTypeInfo.
Now my confusion is some constant values are missing with a particular Database(here Postgres)
If my Source Database's Column Type matches with a Constant Value which is missing in my Target Database then what should I be doing?
Should I map this manually?
Please Help!

Debasis Jana
Anybody can help me out of this?

Debasis Jana
Apr 13 '08 #2
r035198x
13,262 8TB
Now my confusion is some constant values are missing with a particular Database(here Postgres)
..
Could you post an example of the missing constant values?
Apr 14 '08 #3
dmjpro
2,476 2GB
Could you post an example of the missing constant values?
Thanks r035198x!
Actually the does vendor take all the constant values and put a SQL Type Name against name?

Right now i don't remember
OK let me check .. I have a code to run then i ll check manually what constant values are missing.

Debasis Jana
Apr 14 '08 #4
JosAH
11,448 Expert 8TB
Thanks r035198x!
Actually the does vendor take all the constant values and put a SQL Type Name against name?

Right now i don't remember
OK let me check .. I have a code to run then i ll check manually what constant values are missing.

Debasis Jana
I know the answer already without 'running any code'. Every compliant JDBC
interface has to supply a complete Type interface. That doesn't imply that all
those are actually implemented by the database engine. That's where the
DatabaseMetaData comes in.

I'm afraid this turns out to be 'one of those questions' ...

kind regards,

Jos
Apr 14 '08 #5
dmjpro
2,476 2GB
I know the answer already without 'running any code'. Every compliant JDBC
interface has to supply a complete Type interface. That doesn't imply that all
those are actually implemented by the database engine. That's where the
DatabaseMetaData comes in.

I'm afraid this turns out to be 'one of those questions' ...

kind regards,

Jos
hahahahahaah!
yeah my behaviour maid you make a such comment!
Actually i run this code.
What you think that also I tried but I got surprised some constant values are missing.
Neways I am now ...trying to run this code.

Debasis Jana.
Apr 14 '08 #6
dmjpro
2,476 2GB
I know the answer already without 'running any code'. Every compliant JDBC
interface has to supply a complete Type interface. That doesn't imply that all
those are actually implemented by the database engine. That's where the
DatabaseMetaData comes in.

I'm afraid this turns out to be 'one of those questions' ...

kind regards,

Jos

Josh here is my Code.
Expand|Select|Wrap|Line Numbers
  1. ResultSet data_types = db_metadata.getTypeInfo();
  2.         while(data_types.next()){
  3.             int type = data_types.getInt("DATA_TYPE");
  4.             String type_name = data_types.getString("TYPE_NAME");
  5.  
  6.             System.out.println("Type: " + type + "\tType Name: " + type_name);
  7.         }
  8.  
and the missing constants are ....

BLOB 2004
BOOLEAN 16
CLOB 2005
DECIMAL 3

Now I didn't check all the constants.
But If i get any missing then what should i be doing?
What I am trying to Josh to map a source SQL Type to a target SQL type.
Source and target database may not be same.

Debasis Jana.
Apr 14 '08 #7
dmjpro
2,476 2GB
See this link guys.

postgressql bugs
Now one more problem ....
I am now converting from Sybase to Postgres.
Now suppose Sybase implements java.sql.Types.XXX of size 10 but postgres may not implement this type of size more than 10.

Actually what my code does first i am extracting the column types as java.sql.Types.XXX and the column size
Now to convert it into the target database i am calling this method

Expand|Select|Wrap|Line Numbers
  1. /**
  2.      * This method returns  a Database specific column type for a java.sql.Types.XXXX.
  3.      * This also checks that whether the found datatype supports the size given by the source.
  4.      * @param sourceType The java.sql.Types.XXX value.
  5.      * @param sourceSize The source database cloumn size.
  6.      * @param targetConn The target connection for which the column name to be obtained.
  7.      * @return It returns column name for java.sql.Types.XXXX.
  8.      * If not found for java.sql.Types.XXX then returns null;
  9.      * @exception It throws SQLException if any database operation fails.
  10.      */
  11. public String getColumnType(int sourceType,int sourceSize,Connection targetConn) throws SQLException{
  12.         System.out.println("Source Type: " + sourceType + "\tSource Size: " + sourceSize);
  13.         DatabaseMetaData db_metadadta = targetConn.getMetaData();
  14.         ResultSet rs_columns = db_metadadta.getTypeInfo();
  15.         while(rs_columns.next()){
  16.             int type = rs_columns.getInt("DATA_TYPE");
  17.             String name = rs_columns.getString("TYPE_NAME");
  18.             short min_scale = rs_columns.getShort("MINIMUM_SCALE"),
  19.                   max_scale = rs_columns.getShort("MAXIMUM_SCALE");
  20.             if(sourceType==type){
  21.                 System.out.println("Column Type Name: " + name + "\tMinimum Scale: " + min_scale + "\tMaximum Sclae: " + max_scale);
  22.                 if(sourceSize>=min_scale && sourceSize<=max_scale){
  23.                     rs_columns.getStatement().close();
  24.                     return name;
  25.                 }
  26.             }
  27.         }
  28.         rs_columns.getStatement().close();
  29.         return null;
  30.     }
  31.  
Hope all the experts can get my point.

Debasis Jana.
Apr 15 '08 #8
dmjpro
2,476 2GB
See this link guys.

postgressql bugs
Now one more problem ....
I am now converting from Sybase to Postgres.
Now suppose Sybase implements java.sql.Types.XXX of size 10 but postgres may not implement this type of size more than 10.

Actually what my code does first i am extracting the column types as java.sql.Types.XXX and the column size
Now to convert it into the target database i am calling this method

Expand|Select|Wrap|Line Numbers
  1. /**
  2.      * This method returns  a Database specific column type for a java.sql.Types.XXXX.
  3.      * This also checks that whether the found datatype supports the size given by the source.
  4.      * @param sourceType The java.sql.Types.XXX value.
  5.      * @param sourceSize The source database cloumn size.
  6.      * @param targetConn The target connection for which the column name to be obtained.
  7.      * @return It returns column name for java.sql.Types.XXXX.
  8.      * If not found for java.sql.Types.XXX then returns null;
  9.      * @exception It throws SQLException if any database operation fails.
  10.      */
  11. public String getColumnType(int sourceType,int sourceSize,Connection targetConn) throws SQLException{
  12.         System.out.println("Source Type: " + sourceType + "\tSource Size: " + sourceSize);
  13.         DatabaseMetaData db_metadadta = targetConn.getMetaData();
  14.         ResultSet rs_columns = db_metadadta.getTypeInfo();
  15.         while(rs_columns.next()){
  16.             int type = rs_columns.getInt("DATA_TYPE");
  17.             String name = rs_columns.getString("TYPE_NAME");
  18.             short min_scale = rs_columns.getShort("MINIMUM_SCALE"),
  19.                   max_scale = rs_columns.getShort("MAXIMUM_SCALE");
  20.             if(sourceType==type){
  21.                 System.out.println("Column Type Name: " + name + "\tMinimum Scale: " + min_scale + "\tMaximum Sclae: " + max_scale);
  22.                 if(sourceSize>=min_scale && sourceSize<=max_scale){
  23.                     rs_columns.getStatement().close();
  24.                     return name;
  25.                 }
  26.             }
  27.         }
  28.         rs_columns.getStatement().close();
  29.         return null;
  30.     }
  31.  
Hope all the experts can get my point.

Debasis Jana.

Guys I solved that problem. What I am doing for those missing values I am doing it hard-code. One more thing which has minimum-scale and maximum scale zero that can't be of any size.

Debasis Jana
Apr 16 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Aleksey | last post by:
Hello, I have the following problem working with DatabaseMetaData. There is a database with table and attribute names in Russian. Database cluster was initialized with appropriate...
0
by: Jairam Panickssery | last post by:
I have a simple JDBC 2.0(app driver) code snippet like: ########################### cSQL = DriverManager.getConnection(sDBURL, sDBUser, sDBPasswd); DatabaseMetaData dmd = cSQL.getMetaData(); //rs...
3
by: aj | last post by:
Red Hat AS 2.1 DB2 WSE v8.1 FP5 Type 4 DB2 JDBC driver Using java.sql.DatabaseMetaData and ResultSetMetaData, I've written a JDBC/Java utility that shows, table by table, columns & their...
4
by: JMCN | last post by:
object invalid or no longer set - confusion of the recordset in access 2003. i am currently converting from access 97 to access 2003. majority of the codes converted over perfectly fine, though...
0
by: i_have_control | last post by:
I'd be grateful for any input on this one: I have three web domains. The destinations of two are set to folders on the first, though that fact is transparent to the user (i.e: it does not...
2
by: Maroon | last post by:
import java.sql.*; public class TESTA{ TESTA(){} public static int product() { try { Class.forName("com.ibm.db2.jcc.DB2Driver");
10
by: joelagnel | last post by:
hi friends, i've been having this confusion for about a year, i want to know the exact difference between text and binary files. using the fwrite function in c, i wrote 2 bytes of integers in...
1
by: Richard Lewis Haggard | last post by:
I'm having a problem with what appears to be some sort of confusion with references. I have a single solution with a dozen projects which has been working quite nicely for a while. The references...
1
by: jweaver | last post by:
I'm having a problem getting back appropriate metadata for stored procedures from MS SQL Server 2000 and 2005. I've created a simple stored procedure that has an output param that is a cursor. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.