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
8 2359
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
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?
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
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
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.
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. -
ResultSet data_types = db_metadata.getTypeInfo();
-
while(data_types.next()){
-
int type = data_types.getInt("DATA_TYPE");
-
String type_name = data_types.getString("TYPE_NAME");
-
-
System.out.println("Type: " + type + "\tType Name: " + type_name);
-
}
-
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.
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 -
/**
-
* This method returns a Database specific column type for a java.sql.Types.XXXX.
-
* This also checks that whether the found datatype supports the size given by the source.
-
* @param sourceType The java.sql.Types.XXX value.
-
* @param sourceSize The source database cloumn size.
-
* @param targetConn The target connection for which the column name to be obtained.
-
* @return It returns column name for java.sql.Types.XXXX.
-
* If not found for java.sql.Types.XXX then returns null;
-
* @exception It throws SQLException if any database operation fails.
-
*/
-
public String getColumnType(int sourceType,int sourceSize,Connection targetConn) throws SQLException{
-
System.out.println("Source Type: " + sourceType + "\tSource Size: " + sourceSize);
-
DatabaseMetaData db_metadadta = targetConn.getMetaData();
-
ResultSet rs_columns = db_metadadta.getTypeInfo();
-
while(rs_columns.next()){
-
int type = rs_columns.getInt("DATA_TYPE");
-
String name = rs_columns.getString("TYPE_NAME");
-
short min_scale = rs_columns.getShort("MINIMUM_SCALE"),
-
max_scale = rs_columns.getShort("MAXIMUM_SCALE");
-
if(sourceType==type){
-
System.out.println("Column Type Name: " + name + "\tMinimum Scale: " + min_scale + "\tMaximum Sclae: " + max_scale);
-
if(sourceSize>=min_scale && sourceSize<=max_scale){
-
rs_columns.getStatement().close();
-
return name;
-
}
-
}
-
}
-
rs_columns.getStatement().close();
-
return null;
-
}
-
Hope all the experts can get my point.
Debasis Jana.
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 -
/**
-
* This method returns a Database specific column type for a java.sql.Types.XXXX.
-
* This also checks that whether the found datatype supports the size given by the source.
-
* @param sourceType The java.sql.Types.XXX value.
-
* @param sourceSize The source database cloumn size.
-
* @param targetConn The target connection for which the column name to be obtained.
-
* @return It returns column name for java.sql.Types.XXXX.
-
* If not found for java.sql.Types.XXX then returns null;
-
* @exception It throws SQLException if any database operation fails.
-
*/
-
public String getColumnType(int sourceType,int sourceSize,Connection targetConn) throws SQLException{
-
System.out.println("Source Type: " + sourceType + "\tSource Size: " + sourceSize);
-
DatabaseMetaData db_metadadta = targetConn.getMetaData();
-
ResultSet rs_columns = db_metadadta.getTypeInfo();
-
while(rs_columns.next()){
-
int type = rs_columns.getInt("DATA_TYPE");
-
String name = rs_columns.getString("TYPE_NAME");
-
short min_scale = rs_columns.getShort("MINIMUM_SCALE"),
-
max_scale = rs_columns.getShort("MAXIMUM_SCALE");
-
if(sourceType==type){
-
System.out.println("Column Type Name: " + name + "\tMinimum Scale: " + min_scale + "\tMaximum Sclae: " + max_scale);
-
if(sourceSize>=min_scale && sourceSize<=max_scale){
-
rs_columns.getStatement().close();
-
return name;
-
}
-
}
-
}
-
rs_columns.getStatement().close();
-
return null;
-
}
-
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
by: Maroon |
last post by:
import java.sql.*;
public class TESTA{
TESTA(){}
public static int product() {
try {
Class.forName("com.ibm.db2.jcc.DB2Driver");
|
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...
|
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...
|
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.
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |