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
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>")
Arabic data is converting into ???? when java program queries xml payload from Oracle Table using Select statement
I have written a JDBC program to query xml type payload from Oracle table using Select statement. Few XML elements in the payload contains like FirstName, LastName etc. contains Arabic Characters. When i run my program, Select query returning the xml payload but the elements which having arabic characters are converting into ????.
I am not sure why it is happening like this.
is any one have solution for this problem?
Thanks in Advance.
I experienced this problem with java and mysql on eclipse the solution was
From eclipse click right on your project and choose properties and choose utf-8 like this photo
Then from the database chose base encoding and utf-8 tables.
Finally, all database queries must be utf-8 encoded
like this
String url = "jdbc:mysql://host/database?useUnicode=true&characterEncoding=utf8";
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
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