Save xml column data in physical path using java - java

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

Related

How to store file path in database stored in file system

I want to create a separate notes file for each user.
The notes files are kept in a network file system(or the server).
Suppose I have a table employee_info
empid empname pathtofile
50 John \\[filepathfromnetworkfilesystem]\50.txt
51 Max \\[filepathfromnNFS]\51.txt
Which datatype will the 'pathtofile' column be?
I checked BLOB and CLOB, but they store binary, so not sure those are appropriate datatypes here.
And any sample code, how can I access this column from java code to retrieve the contents of the file?
Any help would be appreciated.

Read the table data from the PDF file and save in the MySQL database as it is

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.

Create single xml file from multiple xmls

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>

Extract/Parse XML data/element from BLOB column in Oracle

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

How to convert xml file into mysql?

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

Categories

Resources