I have an xml file which was created from a mysql database with just 1 table.
<database_name>
<table_name>
<col1>row1</col1>
<col2>row1</col1>
</table_name>
<table_name>
<col1>row2</col1>
<col2>row2</col2>
</table_name>
</database_name>
I need to convert this xml file back to a mysql database. How can I do this using Java?
You could use an xml parsing library like dom4j, to parse the file, loop through the results and emit a text file that contains a list of inserts.
Do you know the schema or does it need to be inferred from the data?
So your resultant text file would be something like
create table a ()
insert into a (c1,...cn) values (v1,...vn)
Then you could use mysqldump to push the file into a db
mysqldump -u [username] [databasename] < output.sql
You can write XSL tranformation, and there is no need in Java
Related
I am inserting data from a CSV file to a MySQL database, and one of the columns should contain the SOUNDEX representation of a string.
For example, I have the first name as a column in the CSV and the database should contain its SOUNDEX.
I am using tMap between the file delimited and MySQL output, so the operation should be there. Something like SOUNDEX(row1.FIRST_NAME).
Details: Talend Open Studio, MySQL database
You can use Apache Commons Codec to do this. First load the library using tLibraryLoad:
Then use:
new org.apache.commons.codec.language.Soundex().encode("<string>")
I have a requirement to read the value form a PDF file and save the result in a db.
I have converted Pdf to text .
Now the text data looks like this:
Test Name Results Units Bio. Ref. Interval
LIPID PROFILE, BASIC, SERUM
Cholesterol Total 166.00 mg/dL <200.00
Triglycerides 118.00 mg/dL <150.00
My requirement is to read the table data from the Pdf file and save in the MySQL database as it is.
use java io to read the text file and jdbc to safe the information in the mysql via sql.
I have an sql server database table which has xml column name called "Bodytext" which will store xml data.
Now I need to get this "Bodytext" column data and save into System physical path as xml file(Ex: test.xml etc.,)
Any suggestion how to implement this using JAVA?
The column type would be BLOB or CLOB. Retrieve the column data and write the byte data to your file and make it abc.xml
My requirement is as follows:
I would like to use a JDBC to connect the Oracle which has xml as a table column and retrieve the records. I want all those retrieved xml records to be in one file.
I will parse those extracted xmls using JAXB API and delete some of the tags for every xml i read . Then i would like to generate one single output file which consist of all the xmls that are edited
After retrieving the data from the table my output should look like this
Extracted_records.txt
<Record><tag1></tag1><tag2></tag2><tag3></tag3><Record>
<Record><tag1></tag1><tag2></tag2><tag3></tag3><Record>
<Record><tag1></tag1><tag2></tag2><tag3></tag3><Record>
<Record><tag1></tag1><tag2></tag2><tag3></tag3><Record>
After parsing and deleting the records my output file should look like this
Outputfile.txt
<Record><tag2></tag2><tag3></tag3><Record>
<Record><tag1></tag1><tag2></tag2><Record>
<Record><tag1></tag1><Record>
<Record><tag1></tag1><tag3></tag3><Record>
I have a 2 tables, CONFIGURATION_INFO and CONFIGURATION_FILE. I use the below query to find out all employee files
select i.cfg_id, Filecontent
from CONFIGURATION_INFO i,
CONFIGURATION_FILE f
where i.cfg_id=f.cfg_id
but I also need to parse or extract data from the blob column Filecontent and display all cfg_id whose xml tag PCVERSION starts with 8. Is there any way?
XML tag that needs to be extracted is <CSMCLIENT><COMPONENT><PCVERSION>8.1</PCVERSION></COMPONENT></CSMCLIENT>
XML
It need not be any query, even if it is a java or groovy code, it would help me.
Note: Some of the XMLs might be as big as 5MB.
So basically the data from the table CONFIGURATION_INFO, for the column Filecontent is BLOB?
So the syntax to query out the XML from the BLOB Content from database is using this function XMLType.
This function is converting the datatype of your column from BLOB to XMLType. Then parsing it using XPath function.
Oracle Database
select
xmltype(Filecontent, 871).extract('//CSMCLIENT/COMPONENT/PCVERSION/text()').getstringval()
from CONFIGURATION_INFO ...
do the rest of WHERE logic on your own.
Usally you know what the data in the BLOB column, so you can parse in the SQL query..
If it is a text column (varchar or something like that) you can use to_char(coloumName).
There are a lot of functions that you can use you can find them in this link
Usually you will use to_char/to_date/hexToRow/rowTohex
convert blob to file link