From XML to insert records in a database
I want to ask anyone out there for advice about parsing an XML document preparing its records for insertion into a database table. Below is not a very practical example but gives the gist of what I want to do.
<?xml version="1.0"?>
<MESSAGE>
<CONTACT>
<NAME>David</NAME>
<TEL>34111164</TEL>
<MOB>0422127262</MOB>
</CONTACT>
<CONTACT>
<NAME>Jason</NAME>
<TEL>33279864</TEL>
<MOB>0421127564</MOB>
</CONTACT>
</MESSAGE>
At the moment I have a class which extends DefaultHandler and uses SAX to parse the file and insert each record when it knows it has reached the end of a record. I am looking for an example on how I can do the same job, create values for a PreparedStatement to insert to a database table but using DOM or JDOM. Can anyone point me in the right direction? Yes, I have seen examples for reading XML into a Document using JDOM, but I am looking specifically for an example of what is the best way to prepare XML data for PreparedStatement inserts.
Any pointers would be greatly appreciated.
Thanks in advance.
Matthew
Thanks for the reply.
Unfortunately I am using Informix. I need to write the parser myself. The current SAX parser does the job, however, its a bit rough and dirty. The main aspect of the parser I want to tackle is how I might more easily modify how it parses when the structure of the XML documents change. At the moment for every change in the XML document I have to ammend three to four parts of the parser. In the end I want to write a means to modify a mapping of how an XML document will be parsed. The first step before I start that is to move the current parser from SAX to something like DOM or JDOM.
The SAX parser is straight forward that it hits the end of an element, notifying the code that the variables are ready for the PreparedStatement to be executed, and performs this task continuously till it reaches the end of the XML document. I want to find another way to do it.
Similar Messages
-
Error while inserting records in sqlLite database
Hi all
I am building a hybrid web app in SMP using phonegap and html.
I am trying to insert records in sql database but i get an error with an undefined error code
Please see below :
function openDatabaseFoo() {
db = window.openDatabase(clientDBName, clientDBVersion, clientDBDisplayName, clientDBMaxSize);
function createDBTables() {
db.transaction(function(tx) {
// Create mine table
var fooCreate = 'CREATE TABLE IF NOT EXISTS ' + fooTable+ ' (empNo, empName)';
tx.executeSql(fooCreate , [],
function (tx, resultSet) {
//success
var msg = 'Sucessfully created';
alert(msg);
logSuccessMessage(msg);
function (err) {
//error code
var msg = "Error creating table = " + err.code;
alert(msg);
logErrorMessage(msg);
the creation of tables is happening properly because i am getting a success message in the alerts.
I am getting the error when i am trying to insert records in the above table
function insertDataTable(){
db.transaction(function(tx) {
var insertSql = 'INSERT INTO ' + fooTable + ' (empNo, empName) VALUES ("1603","baker")';
tx.executeSql(insertSql, [],
function (tx, resultSet) {
//success
var msg = 'Sucessful insertingdata.';
alert(msg);
logSuccessMessage(msg);
function (err) {
//error code
var msg = "Error inserting data sql = " + insertSql + " Error code = " + err.code;
alert(msg);
logErrorMessage(msg);
can some one please help.Also guide me where can i check the sqlLite database logs to see more about the error.
I would really appreciate the help.I have been onto this since past few days now
Regards
ShwetaWhat is err.code, or the value of msg when the error occurs?
Thanks,
Andrew. -
How to extract data from xml and insert into Oracle table
Hi,
I have a large xml file. which will have hundreds of the following transaction tags having column names and there values.
There is a table one of the schema with coulums "actualCostRate","billRate"....etc.
I need to extract the values of these columns and insert into the table
<Transaction actualCostRate="0" billRate="0" chargeable="1" clientID="NikuUK" chargeCode="LCOCD1" externalID="L-RESCODE_UK1-PROJ_UK_CNT_GBP-37289-8" importStatus="N" projectID="TESTPROJ" resourceID="admin" transactionDate="2002-02-12" transactionType="L" units="11" taskID="5017601" inputTypeCode="SALES" groupId="123" voucherNumber="ABCVDD" transactionClass="ABCD"/>
<Transaction actualCostRate="0" billRate="0" chargeable="1" clientID="NikuEU" chargeCode="LCOCD1" externalID="L-RESCODE_US1-PROJ_EU_STD2-37291-4" importStatus="N" projectID="TESTPROJ" resourceID="admin" transactionDate="2002-02-04" transactionType="L" units="4" taskID="5017601" inputTypeCode="SALES" groupId="124" voucherNumber="EEE222" transactionClass="DEFG"/>Re: Insert from XML to relational table
http://www.google.ae/search?hl=ar&q=extract+data+from+xml+and+insert+into+Oracle+table+&btnG=%D8%A8%D8%AD%D8%AB+Google&meta= -
Inserting Record in Two Databases
Hello ,
i want to save the record in two database
1 oracle 9i r1
2 MS access
what is the best way to doODBC/JDBC is the best option for this
-
Hi all :)
i think that i have problem in the phase of insertion ...
that's my code :
//insert
declare
i number;
begin
commit_form();
i := show_alert('VALID');
clear_form;
end;
But,when i want to update record ,i encounter this error:
frm-40508 impossible to insert record
Violation unique constraint
Any solutions ?
best regards
Edited by: 979155 on 4 janv. 2013 19:45hi,
I know there are two modes in oracle:
automatic and manual; for manual I mastery but the alternative ideas I just on consultation (using execute_query) but for the update I have not ideas ...
for the button, it is that there must be a trigger (when-button-pressed)? If yes, what it will contain code in pl / sql? -
Inserting records from Infopath forms library to a SQL table
Hi,
I have a requirement where i need to populate records from a Infopath forms library to a SQL table in a database. We have written a console app to achive the same. However we are encountering performance issues when inserting records in the database. The
way we retreive information from Infopath forms library is through a CAML query and then insert record by record in database. Is their a better and faster way to acheive this?
Can someone pls help?
thanks,
Anand
Thanks and Regards, Anand R. DeshpandeHello Anand,
Could you share you console application code? Also tell us when you face performance issue. I mean is there any problem in accessing infopath form or you are facing problem with only console application.
Hemendra:Yesterday is just a memory,Tomorrow we may never see
Please remember to mark the replies as answers if they help and unmark them if they provide no help -
Tsql import from xml to table - sql server 2012 = (o row(s) affected)
Hello,
here is my XML header and footer:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<streetAndCities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<record>
<rowIndex></rowIndex>
<cityCode></cityCode>
<cityName></cityName>
<streetCode></streetCode>
<streetName></streetName>
</record>
</streetAndCities>
with a bunch of <record></record> tags with data inside....
I'm trying to import data from my XML file to my new and empty table with the following code:
DECLARE @xml XML
SELECT @xml = x.y
FROM OPENROWSET( BULK 'c:\st.xml', SINGLE_CLOB ) x(y)
INSERT INTO tblCitiesStreets(rowIndex, cityCode, cityName, streetCode, streetName)
SELECT
x.y.value('(Column[@Name="rowIndex"]/text())[1]', 'INT') rowIndex,
x.y.value('(Column[@Name="cityCode"]/text())[1]', 'NVARCHAR(255)') cityCode,
x.y.value('(Column[@Name="cityName"]/text())[1]', 'NVARCHAR(255)') cityName,
x.y.value('(Column[@Name="streetCode"]/text())[1]', 'NVARCHAR(255)') streetCode,
x.y.value('(Column[@Name="streetName"]/text())[1]', 'NVARCHAR(255)') streetName
FROM @xml.nodes('Root/DataRow') AS x(y)
but the output I get is
(0 row(s) affected)
and of course when I select * from tblCitiesStreets, the table is empty.
what is wrong with the code?
regardsNothing's wrong with your code. You're working with the wrong file OR - I guess - you have copied those XPath expressions without further looking at them..
This works with your XML:
DECLARE @xml XML = N'
<streetAndCities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<record>
<rowIndex>1</rowIndex>
<cityCode>2</cityCode>
<cityName>3</cityName>
<streetCode>4</streetCode>
<streetName>5</streetName>
</record>
</streetAndCities>';
SELECT Record.value('rowIndex[1]', 'INT') rowIndex ,
Record.value('cityCode[1]', 'NVARCHAR(255)') cityCode ,
Record.value('cityName[1]', 'NVARCHAR(255)') cityName ,
Record.value('streetCode[1]', 'NVARCHAR(255)') streetCode ,
Record.value('streetName[1]', 'NVARCHAR(255)') streetName
FROM @xml.nodes('streetAndCities/record') AS StreetsAndCities ( Record ); -
I've got an ASP page which inserts a record into an Access
database.
Basically the user can insert a record which is one of 4
types. They
all go into the same table, just different fields are
completed in the form.
I'd like to be able to hide the irrelevant form fields from
the user
depending on the type of record they are entering. I did this
using
some simple If statements.
However the Insert Record server behaviour isn't happy - when
I click
the submit button, I get an error that one of the parameters
has no
default value. The parameter referred to is one of the form
fields I've
chosen not to display with the If statements.
Is there a way around this, or am I going to have to create 4
different
insert record forms, one for each type?
Hope that makes sense.
Thanks
VixNo, all the field names in the Access database are fine as
far as I can see.
I don't understand where that parameter ?_5 is coming from.
The insert record code looks like this, if it helps:
Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_certsConn_STRING
MM_editCmd.CommandText = "INSERT INTO tblCerts (Surname,
FirstNames, Gender, EventDate, SpouseSurname,
SpouseFirstNames,
DateOfAdoption, Town, Country, County, Type, MemberID) VALUES
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append
MM_editCmd.CreateParameter("param1",
202, 1, 50, Request.Form("Surname")) ' adVarWChar
MM_editCmd.Parameters.Append
MM_editCmd.CreateParameter("param2",
202, 1, 255, Request.Form("FirstNames")) ' adVarWChar
MM_editCmd.Parameters.Append
MM_editCmd.CreateParameter("param3",
202, 1, 50, Request.Form("Gender")) ' adVarWChar
MM_editCmd.Parameters.Append
MM_editCmd.CreateParameter("param4",
135, 1, -1, MM_IIF(Request.Form("EventDate"),
Request.Form("EventDate"),
null)) ' adDBTimeStamp
MM_editCmd.Parameters.Append
MM_editCmd.CreateParameter("param5",
202, 1, 50, Request.Form("SpouseSurname")) ' adVarWChar
MM_editCmd.Parameters.Append
MM_editCmd.CreateParameter("param6",
202, 1, 50, Request.Form("SpouseFirstNames")) ' adVarWChar
MM_editCmd.Parameters.Append
MM_editCmd.CreateParameter("param7",
135, 1, -1, MM_IIF(Request.Form("DateOfAdoption"),
Request.Form("DateOfAdoption"), null)) ' adDBTimeStamp
MM_editCmd.Parameters.Append
MM_editCmd.CreateParameter("param8",
202, 1, 50, Request.Form("Town")) ' adVarWChar
MM_editCmd.Parameters.Append
MM_editCmd.CreateParameter("param9",
202, 1, 50, Request.Form("Country")) ' adVarWChar
MM_editCmd.Parameters.Append
MM_editCmd.CreateParameter("param10",
202, 1, 50, Request.Form("County")) ' adVarWChar
MM_editCmd.Parameters.Append
MM_editCmd.CreateParameter("param11",
202, 1, 50, Request.Form("Type")) ' adVarWChar
MM_editCmd.Parameters.Append
MM_editCmd.CreateParameter("param12",
5, 1, -1, MM_IIF(Request.Form("MemberID"),
Request.Form("MemberID"),
null)) ' adDouble
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
Baxter wrote:
> Do you have a question mark (?) in your field name. If
so remove it, as some
> database engines, including Microsoft Access, and should
not be used in
> database table names or field names.
> Dave
> "Vix" <[email protected]> wrote in message
> news:[email protected]...
>> I've already done that. Allow zero length is set to
Yes on those fields.
>>
>> The error I get is
>> Microsoft JET Database Engine error '80040e10'
>>
>> Parameter ?_5 has no default value.
>>
>> /add_certificates.asp, line 89
>>
>> line 89 is the execute command for the insert
record.
>> I'm presuming that the parameter being referred to
is this one
>>
>> MM_editCmd.Parameters.Append
MM_editCmd.CreateParameter("param5",
>> 202, 1, 50, Request.Form("SpouseSurname")) '
adVarWChar
>>
>> which is the first of the "hidden" fields.
>>
>> Any other ideas?
>>
>>
>> Baxter wrote:
>>> Just tell access to accept null values for the
fields that you are not
>>> showing at the time and it should work fine.
>>> Dave
>>> "Vix" <[email protected]> wrote in message
>>> news:[email protected]...
>>>> I've got an ASP page which inserts a record
into an Access database.
>>>>
>>>> Basically the user can insert a record which
is one of 4 types. They
>>>> all go into the same table, just different
fields are completed in the
>>> form.
>>>> I'd like to be able to hide the irrelevant
form fields from the user
>>>> depending on the type of record they are
entering. I did this using
>>>> some simple If statements.
>>>>
>>>> However the Insert Record server behaviour
isn't happy - when I click
>>>> the submit button, I get an error that one
of the parameters has no
>>>> default value. The parameter referred to is
one of the form fields
> I've
>>>> chosen not to display with the If
statements.
>>>>
>>>> Is there a way around this, or am I going to
have to create 4 different
>>>> insert record forms, one for each type?
>>>>
>>>> Hope that makes sense.
>>>>
>>>> Thanks
>>>> Vix
>>>
>
> -
I have a database for an operational application & I am trying to build some simple insert pages to insert records into the database.
I have constructed the insert forms, yet when I try to inserta record, the primary key is not automatically applying to the record, as is an auto-number that should apply to another field? yet the data is populatin within the table? I am assuming that the database would apply this automatically as it does in the application??
what am i missing?
Thanks
PeteHi
Thanks for the response.
I have edited the insert statement to take these fields out, however when I insert a record it does go into the database, but again the primary key & the autonumber do not increment?
If i try to enter another record i get
Duplicate entry '' for key 'PRIMARY'
Thanks
Pete -
How to insert records in database from a dataset with multiple tables
Hi,
I'm struggling with the following problem:
I have saved a dataset to an XML file by executing the following statement:
ds.WriteXml( "Export\\ModuleChain_Mdata.xml" );The dataset, ds, includes records from several tables.
Is there an easy way to retrieve those records to the database, I.E inserting them again?
regards Peteryou can try Associative Arrays:
http://www.oracle.com/technology/oramag/oracle/07-jan/o17odp.html
you need to convert yore DataTables to array first and than pass them in to the associative array procedure. -
Retrive last inserted record from database table
Hi,
some body inserting a record into table 'A' through some procedure/java program.i want to retrive the last inserted record from database table.records are not stored in order.Can any body help me.In general, unless you are storing a timestamp as part of the row or you have some sort of auditing in place, Oracle has no idea what the "first" or "last" record in a table is. Nor does it track when a row was inserted.
- If you have the archived logs from the point in time when the row was inserted, you could use LogMiner to find the timestamp
- If the insert happened recently (i.e. within hours), you may be able to use flashback query to get the value
- If you're on 10g or later and the table was built with ROWDEPENDENCIES and the insert happened in the last few days and you can deal with a granularity of a few seconds and you don't need 100% accuracy, you could get the ORA_ROWSCN of the row and convert that to a timestamp.
If this is something you contemplate needing, you need to store the data in the row or set up some sort of auditing.
Justin -
Inserting records from a txt file to a database table
I would like to know how to insert records from a file (txt) to a database table through a java application?
[BufferedReader |http://java.sun.com/javase/6/docs/api/java/io/BufferedReader.html] and PreparedStatement
IO and JDBC -
Inserting nested records from XML to DB
Hi,
I am facing a problem with inserting nested records in XML to DB. For example, I have this XML:
<?xml version="1.0" encoding="utf-8" ?>
<ns0:CutLOTUpdate xmlns:ns0="http://LayoutTracking/v1.0">
<C>1</C>
<COMMENTS>Main1</COMMENTS>
<CUT_DATA>
<CUT>
<D>1</D>
<COMMENTS>2Main1</COMMENTS>
<IT>
<E>11</E>
<COMMENTS>3Det1</COMMENTS>
</IT>
<IT>
<E>12</E>
<COMMENTS>3Det2</COMMENTS>
</IT>
</CUT>
<CUT>
<D>2</D>
<COMMENTS>2Main2</COMMENTS>
<IT>
<E>21</E>
<COMMENTS>3Det1</COMMENTS>
</IT>
<IT>
<E>22</E>
<COMMENTS>3Det2</COMMENTS>
</IT>
</CUT>
</CUT_DATA>
</ns0:CutLOTUpdate>
I would like to insert these data into the following table in a denormalized form:
CREATE TABLE A (
C NUMBER,
D NUMBER,
E NUMBER,
C_COMMENTS VARCHAR2(50),
D_COMMENTS VARCHAR2(50),
E_COMMENTS VARCHAR2(50))
I have tried using this procedure:
CREATE OR REPLACE PROCEDURE insc (Cut_Clob CLOB) AS
Cut XMLType;
BEGIN
/*Converts Cut_Clob parameter into XML */
Cut := sys.xmltype.createXML(Cut_Clob);
/*Inserts data from XML to table*/
INSERT INTO a
( C ,
C_COMMENTS ,
D ,
D_COMMENTS ,
E ,
E_COMMENTS )
SELECT DISTINCT
ExtractVALUE(CUT, '/ns0:CutLOTUpdate/C' , 'xmlns:ns0="http://LayoutTracking/v1.0') C,
ExtractValue(CUT, '/ns0:CutLOTUpdate/COMMENTS', 'xmlns:ns0="http://LayoutTracking/v1.0') C_COMMENTS,
ExtractVALUE(value(ct), '/CUT/D') D,
ExtractValue(value(ct), '/CUT/D_COMMENTS') D_COMMENTS,
ExtractVALUE(value(it), '/IT/E') E,
ExtractValue(value(it), '/IT/E_COMMENTS') E_COMMENTS
FROM TABLE (xmlsequence(extract(CUT,'/ns0:CutLOTUpdate/CUT_DATA/CUT','xmlns:ns0="http://LayoutTracking/v1.0'))) ct,
TABLE (xmlsequence(extract(CUT,'/ns0:CutLOTUpdate/CUT_DATA/CUT/IT','xmlns:ns0="http://LayoutTracking/v1.0'))) it;
COMMIT;
END;
However, this resulted into a cartesian product.
Is it possible for me to insert this XML into such table? If yes, can anyone show me how?
I apologize if this seems trivial to you and I appreciate your time for helping me.
Thank you,
KayeHi,
I have tried:
FROM TABLE (xmlsequence(extract(CUT,'/ns0:CutLOTUpdate/CUT_DATA/CUT','xmlns:ns0="http://LayoutTracking/v1.0'))) ct,
TABLE (xmlsequence(extract(CUT,'/ns0:CutLOTUpdate/CUT_DATA/CUT/IT','xmlns:ns0="http://LayoutTracking/v1.0'))) it;
This did not work - resulting in Cartesian product.
I am working with Oracle 10g DB 10.2.0.1.
If it's not too much, I am hoping that someone could show me a script to parse this XML and actually place it in a denormalized form.
If you think this is not possible, can you please just point me to an example where the same XML (with nested information) can be inserted into 3 different tables (relational)?
I have tried searching on different sources, to no avail. I am a beginner on this... I apologize for any inconveniece caused. -
Inserting records from internal table to database table
Hi all,
i want to insert records from internal table to zDatabase table, can u plz guide me which statement is better in performance to insert the records.
1) insert one by one record from internal table
loop at itab.
insert ztable from wa.
endloop.
2) insert total records at a time
INSERT <dbtabname> CLIENT SPECIFIED FROM TABLE itab.
or let me know if any other statement is there with high performance.
i internal table contains nearly 40000 records.
thanks.Hi,
Insert the entire table at atime rather than a record so as to increase the performance.
you can use INSERT <dbtabname> CLIENT SPECIFIED FROM TABLE itab.
or
MODIFY ZPRODUCT FROM TABLE GI_AFPO.
Regards,
Raj. -
Can you use ESB to insert multiple records into a Database
We have an XML file that has a Parent/Child relationship.
In situation 1 we have a single parent record in the xml file. We can insert the record into the database successfully.
In situation 2 we have a parent and a an associated child record. By using a filter expression to identify the existence of the child record we can route to the first DB Adapter to insert the parent then to the second DB Adapter to insert the child.
Is this final scenario logical and also possible.
Situation 3 we have multiple child records associated to a single parent. So we would first insert the parent record then insert all the child records.
ThanksI use PL/SQL for this if you are using Oracle.
Have a look at this post, it is for AQ but the concept can be used for PL/SQL
Re: Can I pass a pl/sql table as a parameter from a database adaptor
I will send you an example
cheers
James
Maybe you are looking for
-
I just downloaded iTunes to my Thinkpad, as part of the installation of my new Nano. The iTunes screen is in this horrible purple and I can't figure out how to change the color screen to the classic grey. When you look at the songs listed it is dark
-
Urgent :::::.i WISH TO DO THIS WITH JDOM and JAVA .
file A.XML <XML> <TP> <FF> </FF> </TP> </XML> file B.XML <XML> <TP> <GG> </GG> </TP> </XML> I WANT TO PASTE node GG in b.xml to a.xml like this <XML> <TP> <FF> <GG> </GG> </FF> </TP> </XML> i WISH TO DO THIS WITH JDOM and JAVA . Please let me know ho
-
Idsconfig, DSEE, and ldapclient error
I've used idsconfig on both Solaris 10 11/06 and Solaris Express b73 to generate a profile that uses proxy credentials and simple authentication. When I run ldapclient on a system to setup the client binding, I get this: [root@ldap-client1 ~]# ldapcl
-
ITunes Store language settings or using an overseas store?
Is there any way to change the Japan iTunes Store interface to display English instead of Japanese? Or failing that, is there any way to use the US or UK stores if I only have a Japan credit card?
-
Windows 2000 users abandoned?
When I recently tried to buy an album I got a message box telling me to upgrade to v7.4.1 or later. This version is for XP or Vista. With Windows 2000, I am upgraded as far as I can go to v7.3.2.6. After several emails back and forth to iTunes suppor