I am having two different tables.I am fetching the value from a column of Table1 and then inserting it into a Column of Table2.No processing is done for that data in between, before inserting into secTable2.Both source and destination tables have same datatype - varchar(50). Example data in Column: CSC123
When I query from destination table with SQL query (after insertion is done),Only 0 appears.When I export the results to excel,I could see some special characters before that 0 (Something like squares). This issue happens only for some cases and the actual data is missing.
Application : J2EE
Framework : Hibernate
Database : Oracle
Please suggest a solution
Thanks
Related
I am trying to write java code to migrate data from oracle database to other database.
My use case is that different client have different version of code and so the database columns may vary. Clients with later version have additional column.
For eg : Client with new version as COL99 in the table SAMPLE_TABLE.
While writing the migration code, if I try to select the COL99 from SAMPLE_TABLE, it will work fine for the new client. But for clients on old version, the code fails with
ORA-00904 Invalid Identifier error.
Is there a way to handle in sql query or java code such that, if the column doesn't exist in the database table, simply ignore and do not return the value instead of throwing the exception.
You should first check, whether COL99 exists for your current database connection.
For Oracle you can use a query like this:
SELECT
COL.COLUMN_ID,
COL.OWNER AS SCHEMA_NAME,
COL.TABLE_NAME,
COL.COLUMN_NAME
FROM
SYS.ALL_TAB_COLUMNS COL
INNER JOIN
SYS.ALL_TABLES T
ON COL.OWNER = T.OWNER
AND
COL.TABLE_NAME = T.TABLE_NAME
WHERE
COL.OWNER = 'SCHEMA'
AND
COL.TABLE_NAME = 'SAMPLE_TABLE'
AND
COL.COLUMN_NAME = 'COL99'
Then you create your query with or without COL99.
I need to insert data from excel to database which looks:
Id Name Phone Joining Date Subject
1 A 11111 14-Mar-2001 Cse
2 B 22222 25-Dec-2016 IT
3 C 33333 12-Dec-2011 ECE
If I have to perform batch insert in a single table then I am able to do it using spring jdbctemplate(batchUpdate(...)).
But I want it to insert data in multiple tables e.g. 1st 3 columns in Table1, next 2 in Table2, next n in table3 like this way.
For reading data I am using POI API and after extracting data m keeping it in List of Map object which looks:
allObj=[{0=1.0, 1=A, 2=11111.0, 3=2001-3-14 0:0:0, 4=Cse}, {0=2.0, 1=B, 2=22222.0, 3=2016-12-25 0:0:0, 4=IT}, {0=3.0, 1=C, 2=33333.0, 3=2011-12-12 0:0:0, 4=ECE}]
How to perform this tasks? not asking full solution but a hint. Thanks
If coding is required then inform I am not posting it as it is lengthy and common.
EDITED:
Few didn't understand the Question!
I think u know batch update. I am using JdbcTemplate of spring.
suppose I have table T1 as:
Id|Name|Phone|Joining Date| Subject in Database(using MYSQL)
Now, I have an excel file with the corresponding values.I can read it and batch insert it into database by JdbcTemplate in that table.
But Now I have two table as T1: Id|Name|Phone
and T2: Joining Date| Subject
I have the same excel file.
NOW my question comes into the frame.
How to insert the values in two tables? If you get the question kindly remove your -ve vote.
LOAD DATA LOCAL INFILE
'C:\\temp\\file.csv'
INTO TABLE table_name
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(#col1,#col2)
set
column1 = #col1,
column2 = #col2;
Above query for table1, run same for other tables by changing column_names accordingly.
We are dealing with sybase database in core java code. We are using org.eobjects.metamodel.DataContext to parse query.
String sCol[]=table.getColumnNames();
Query query=dataContext.query().from(table.getName()).select(sCol).toQuery();
return new QueryIterator(dataContext.executeQuery(query).iterator());
But it executing query. Same code working fine with Oracle database to parse and execute query.
Some of query example generated are :
select City.CityName from ownername.City
select City.CityName from City
select CityName from ownername.City
select CityName from City
select ownername.City.CityName from ownername.City
SELECT "City"."CityName" FROM ownername."City"
select * from ownername.City
No any of above query executed. We are getting these errors :
Not capable of parsing FROM token: "ownername"."City"
Could not execute query: The column prefix '"City"' does not match with a table name or alias name used in the query. Either the table is not specified in the FROM clause or it has a correlation name which must be used instead.
Not capable of parsing SELECT token: ownername.City.CityName
How can we execute query using metamodel wih SYBASE database OR is there any other way to execute sybase queries?
Oracle (and Microsoft) use a schema logical construct that Sybase ASE does not. In SAP/Sybase ASE, all tables and columns in a database are in the same schema. It is possible to users to have their own objects in the database though, so there is the possibility of imitating some of the schema behavior using user ownership, but it would require an extra level of effort.
For Sybase the proper query syntax would be:
SELECT [ Col1, Col2 | * ]
FROM [dbName].[ownerName.]TABLE
In your case
SELECT CityName
FROM dbName.ownername.City
In Sybase ASE, it's typically best practice to have all objects owned by 'dbo', so in that case you can omit the owner from the query:
SELECT CityName
FROM dbName..City
Full query syntax and information can be found in the Query Section of the Transact SQL Users Guide in the documentation.
The error messages you're getting are coming from MetaModel's query parser layer. It is searching for matching column and table names in the metadata of your database before it's even firing the query.
I notice that you're using namespace "org.eobjects.metamodel". You should upgrade to Apache MetaModel ("org.apache.metamodel") if possible since a lot has been improved in MetaModel since it's introduction into Apache. Including a lot of query parser improvements.
I have a java Map (Map) and a JDBC connection to hive server.
The schema of the table at the server contains a column of type Map.
Is it possible to insert the java Map to the hive table column with similar datatype using JDBC?
I tried:
"create table test(key string, value Map<String, String>)"
"insert into table test values ('keywer', map('subkey', 'subvalue')) from dummy limit 1;"
ref: Hive inserting values to an array complex type column
but the insert failed with:
"Error: Error while compiling statement: FAILED: ParseException line 1:69 missing EOF at 'from' near ')' (state=42000,code=40000)"
[EDIT]
hive version is : 0.14.0
Thanks
The manual clearly says you cannot insert into a Map data type using SQL:
"Hive does not support literals for complex types (array, map, struct, union), so it is not possible to use them in INSERT INTO...VALUES clauses. This means that the user cannot insert data into a complex datatype column using the INSERT INTO...VALUES clause.”
I think the correct DDL and query would be:
CREATE TABLE test(key STRING, value MAP<STRING, STRING>);
INSERT INTO TABLE test VALUES('keywer', map('subkey', 'subvalue')) from dummy limit 1;
A working method to put a complex type from jdbc client is:
insert into table test select "key",map("key1","value1","key2","value2") from dummy limit 1;
where dummy is another table which has at least one row.
I have exported some data from schema A (table x)to XML and I am reading the XML and inserting the data into schema B(table y). while inserting the data after 20000 records it says
com.ibm.db2.jcc.am.SqlSyntaxErrorException: [jcc][t4][20111][11366][3.63.75] The value of a host variable is too large for its corresponding use. Host variable=1. ERRORCODE=-4461, SQLSTATE=42815
com.ibm.db2.jcc.am.BatchUpdateException: [jcc][t4][102][10040][3.63.75] Batch failure.
The batch was submitted, but at least one exception occurred on an individual member of the batch.
I compared the data types of the corresponding columns in table x and table y they are the same. It is BIGINT for the identity(Auto increment) col and LONG VARCHAR in both source and destination..
Kindly help in resolving this issue.
I had a similar problem one time. I solved it adding to the XML the queue size. In my case was something like this:
<task>
<name>Ventas MCC</name>
<queueSize>100</queueSize>
<queueNames>trashQueue</queueNames>
<queryTasks>
<queryTask>...</queryTask>
</queryTasks>
</task>
With the queueSize the queries was launched in batch.