Read XML into the database
Hi,
If I have a XML file and want to read its attributes into matching columns in a table, what is the best way to map the xml e.g. firstname to a firstname column in the table?
<name>
<firstname>Bill</firstname>
<last>Gates</last>
</name>
Thanks
Why do you want to do this? (Might help with the answer).
Similar Messages
-
How to load a XML file into the database
Hi,
I've always only loaded data into the database by using SQL-Loader and the data format was Excel or ASCII
Now I have to load a XML.
How can I do?
The company where I work has Oracle vers. 8i (don't laugh, please)
Thanks in advance!Hi,
Tough job especially if the XML data is complex. The have been some similar question in the forum:
Using SQL Loader to load an XML File -- use 1 field's data for many records
SQL Loader to upload XML file
Hope they help.
Regards,
Sujoy -
Capture Web Cam image in APEX and Upload into the Database
Overview
By using a flash object, you should be able to interface with a usb web cam connected to the client machine. Their are a couple of open source ones that I know about, but the one I chose to go with is by Taboca Labs and is called CamCanvas. This is released under the MIT license, and it is at version 0.2, so not very mature - but in saying that it seems to do the trick. The next part is to upload a snapshot into the database - in this particular implementation, it is achieved by taking a snapshot, and putting that data into the canvas object. This is a new HTML5 element, so I am not certain what the IE support would be like. Once you have the image into the canvas, you can then use the provided function convertToDataURL() to convert the image into a Base64 encoded string, which you can then use to convert into to a BLOB. There is however one problem with the Base64 string - APEX has a limitation of 32k for and item value, so can't be submitted by normal means, and a workaround (AJAX) has to be implemented.
Part 1. Capturing the Image from the Flash Object into the Canvas element
Set up the Page
Required Files
Download the tarball of the webcam library from: https://github.com/taboca/CamCanvas-API-/tarball/master
Upload the necessary components to your application. (The flash swf file can be got from one of the samples in the Samples folder. In the root of the tarball, there is actually a swf file, but this seems to be a different file than of what is in the samples - so I just stick with the one from the samples)
Page Body
Create a HTML region, and add the following:
<div class="container">
<object id="iembedflash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="320" height="240">
<param name="movie" value="#APP_IMAGES#camcanvas.swf" />
<param name="quality" value="high" />
<param name="allowScriptAccess" value="always" />
<embed allowScriptAccess="always" id="embedflash" src="#APP_IMAGES#camcanvas.swf" quality="high" width="320" height="240"
type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" mayscript="true" />
</object>
</div>
<p><a href="javascript:captureToCanvas()">Capture</a></p>
<canvas style="border:1px solid yellow" id="canvas" width="320" height="240"></canvas>That will create the webcam container, and an empty canvas element for the captured image to go into.
Also, have a hidden unprotected page item to store the Base64 code into - I called mine P2_IMAGE_BASE64
HTML Header and Body Attribute
Add the Page HTML Body Attribute as:
onload="init(320,240)"
JavaScript
Add the following in the Function and Global Variable Declarations for the page (mostly taken out of the samples provided)
//Camera relations functions
var gCtx = null;
var gCanvas = null;
var imageData = null;
var ii=0;
var jj=0;
var c=0;
function init(ww,hh){
gCanvas = document.getElementById("canvas");
var w = ww;
var h = hh;
gCanvas.style.width = w + "px";
gCanvas.style.height = h + "px";
gCanvas.width = w;
gCanvas.height = h;
gCtx = gCanvas.getContext("2d");
gCtx.clearRect(0, 0, w, h);
imageData = gCtx.getImageData( 0,0,320,240);
function passLine(stringPixels) {
//a = (intVal >> 24) & 0xff;
var coll = stringPixels.split("-");
for(var i=0;i<320;i++) {
var intVal = parseInt(coll);
r = (intVal >> 16) & 0xff;
g = (intVal >> 8) & 0xff;
b = (intVal ) & 0xff;
imageData.data[c+0]=r;
imageData.data[c+1]=g;
imageData.data[c+2]=b;
imageData.data[c+3]=255;
c+=4;
if(c>=320*240*4) {
c=0;
gCtx.putImageData(imageData, 0,0);
function captureToCanvas() {
flash = document.getElementById("embedflash");
flash.ccCapture();
var canvEle = document.getElementById('canvas');
$s('P2_IMAGE_BASE64', canvEle.toDataURL());//Assumes hidden item name is P2_IMAGE_BASE64
clob_Submit();//this is a part of part (AJAX submit value to a collection) two
}In the footer region of the page (which is just a loading image to show whilst the data is being submitted to the collection [hidden by default]) :<img src="#IMAGE_PREFIX#processing3.gif" id="AjaxLoading"
style="display:none;position:absolute;left:45%;top:45%;padding:10px;border:2px solid black;background:#FFF;" />If you give it a quick test, you should be able to see the webcam feed and capture it into the canvas element by clicking the capture link, in between the two elements - it might through a JS error since the clob_Submit() function does not exist yet.
*Part 2. Upload the image into the Database*
As mentioned in the overview, the main limitation is that APEX can't submit values larger than 32k, which I hope the APEX development team will be fixing this limitation in a future release, the workaround isn't really good from a maintainability perspective.
In the sample applications, there is one that demonstrates saving values to the database that are over 32k, which uses an AJAX technique: see http://www.oracle.com/technetwork/developer-tools/apex/application-express/packaged-apps-090453.html#LARGE.
*Required Files*
From the sample application, there is a script you need to upload, and reference in your page. So you can either install the sample application I linked to, or grab the script from the demonstration I have provided - its called apex_save_large.js.
*Create a New Page*
Create a page to Post the large value to (I created mine as 1000), and create the following process, with the condition that Request = SAVE. (All this is in the sample application for saving large values).declare
l_code clob := empty_clob;
begin
dbms_lob.createtemporary( l_code, false, dbms_lob.SESSION );
for i in 1..wwv_flow.g_f01.count loop
dbms_lob.writeappend(l_code,length(wwv_flow.g_f01(i)),wwv_flow.g_f01(i));
end loop;
apex_collection.create_or_truncate_collection(p_collection_name => wc_pkg_globals.g_base64_collection);
apex_collection.add_member(p_collection_name => wc_pkg_globals.g_base64_collection,p_clob001 => l_code);
htmldb_application.g_unrecoverable_error := TRUE;
end;I also created a package for storing the collection name, which is referred to in the process, for the collection name:create or replace
package
wc_pkg_globals
as
g_base64_collection constant varchar2(40) := 'BASE64_IMAGE';
end wc_pkg_globals;That is all that needs to be done for page 1000. You don't use this for anything else, *so go back to edit the camera page*.
*Modify the Function and Global Variable Declarations* (to be able to submit large values.)
The below again assumes the item that you want to submit has an item name of 'P2_IMAGE_BASE64', the condition of the process on the POST page is request = SAVE, and the post page is page 1000. This has been taken srtaight from the sample application for saving large values.//32K Limit workaround functions
function clob_Submit(){
$x_Show('AjaxLoading')
$a_PostClob('P2_IMAGE_BASE64','SAVE','1000',clob_SubmitReturn);
function clob_SubmitReturn(){
if(p.readyState == 4){
$x_Hide('AjaxLoading');
$x('P2_IMAGE_BASE64').value = '';
}else{return false;}
function doSubmit(r){
$x('P2_IMAGE_BASE64').value = ''
flowSelectAll();
document.wwv_flow.p_request.value = r;
document.wwv_flow.submit();
}Also, reference the script that the above code makes use of, in the page header<script type="text/javascript" src="#WORKSPACE_IMAGES#apex_save_large.js"></script>Assuming the script is located in workspace images, and not associated to a specific app. Other wise reference #APP_IMAGES#
*Set up the table to store the images*CREATE TABLE "WC_SNAPSHOT"
"WC_SNAPSHOT_ID" NUMBER NOT NULL ENABLE,
"BINARY" BLOB,
CONSTRAINT "WC_SNAPSHOT_PK" PRIMARY KEY ("WC_SNAPSHOT_ID")
create sequence seq_wc_snapshot start with 1 increment by 1;
CREATE OR REPLACE TRIGGER "BI_WC_SNAPSHOT" BEFORE
INSERT ON WC_SNAPSHOT FOR EACH ROW BEGIN
SELECT seq_wc_snapshot.nextval INTO :NEW.wc_snapshot_id FROM dual;
END;
Then finally, create a page process to save the image:declare
v_image_input CLOB;
v_image_output BLOB;
v_buffer NUMBER := 64;
v_start_index NUMBER := 1;
v_raw_temp raw(64);
begin
--discard the bit of the string we dont need
select substr(clob001, instr(clob001, ',')+1, length(clob001)) into v_image_input
from apex_collections
where collection_name = wc_pkg_globals.g_base64_collection;
dbms_lob.createtemporary(v_image_output, true);
for i in 1..ceil(dbms_lob.getlength(v_image_input)/v_buffer) loop
v_raw_temp := utl_encode.base64_decode(utl_raw.cast_to_raw(dbms_lob.substr(v_image_input, v_buffer, v_start_index)));
dbms_lob.writeappend(v_image_output, utl_raw.length(v_raw_temp),v_raw_temp);
v_start_index := v_start_index + v_buffer;
end loop;
insert into WC_SNAPSHOT (binary) values (v_image_output); commit;
end;Create a save button - add some sort of validation to make sure the hidden item has a value (i.e. image has been captured). Make the above conditional for request = button name so it only runs when you click Save (you probably want to disable this button until the data has been completely submitted to the collection - I haven't done this in the demonstration).
Voila, you should have now be able to capture the image from a webcam. Take a look at the samples from the CamCanvas API for extra effects if you wanted to do something special.
And of course, all the above assumed you want a resolution of 320 x 240 for the image.
Disclaimer: At time of writing, this worked with a logitech something or rather webcam, and is completely untested on IE.
Check out a demo: http://apex.oracle.com/pls/apex/f?p=trents_demos:webcam_i (my image is a bit blocky, but i think its just my webcam. I've seen others that are much more crisp using this) Also, just be sure to wait for the progress bar to dissappear before clicking Save.
Feedback welcomed.Hmm, maybe for some reason you aren't getting the base64 version of the saved image? Is the collection getting the full base64 string? Seems like its not getting any if its no data found.
The javascript console is your friend.
Also, in the example i used an extra page, from what one of the examples on apex packages apps had. But since then, I found this post by Carl: http://carlback.blogspot.com/2008/04/new-stuff-4-over-head-with-clob.html - I would use this technique for submitting the clob, over what I have done - as its less hacky. Just sayin. -
Page level validation to prevent duplicate data entry into the database
Hello,
Can anyone please help me out with this issue.
I have a form with two items based on a table. I already have an item level validation to check for null. Now I would like to create a page level validation to check that duplicate data are not entered into the database. I would like to check the database when the user clicks on ‘Create’ button to ensure they are not inserting duplicate record. If data already exist, then show the error message and redirect them to another page. I am using apex 3.2
ThanksHi,
Have you tried writing a PLSQL function to check this?
I haven't tested this specifically, but something like this should work:
1) Create a Page Level Validation
2) Choose PLSQL for the method
3) Choose Function Returning Boolean for the Type
For the validation code, you could do something like this:
DECLARE
v_cnt number;
BEGIN
select count(*)
into v_cnt
from
your_table
where
col1 = :P1_field1 AND
col2 = :P2_field2;
if v_cnt > 0 then return false;
else return true;
end if;
END;If the query returns false, then your error message will be displayed.
Not sure how you would go about redirecting after this page though. Maybe just allow the user to try again with another value (in case they made a mistake) or just press a 'cancel' button to finish trying to create a new record.
Amanda. -
WEBUTIL_PG.WRITE_DATA( ) and uploading documents into the database
When we run our Forms application through Forms Builder, with the user account utilized by our actual users, we're able to upload a file into the database using webutil. This particular database user account is restricted to only the tables and packages it needs access to, granting the full SELECT, INSERT, UPDATE, DELETE to the tables, and then EXECUTE on the packages.
However, when our Developers use their personal database accounts, which essentially have SELECT ANY .. EXECUTE ANY ... etc, this upload process is halted within webutil.pll when it calls the database PACKAGE procedure WEBUTIL_PG.WRITE_DATA( ). It just hangs on that step.
When you look in OEM, during that hang the graph is showing high levels of "Network" activity. Just a solid plateau. We can't figure out why the difference between these accounts has an effect. Does someone see a pattern here that we're missing?
Thanks,
--=Chuck"Still sounds like a permissions issue to me." I know right?
So I logged in as myself. I have DBA privileges in the database. The call to the database package hung for me as well. No error ... just a hung cursor.
As for debugging ... the call to WEBUTIL_PG hangs, when the Forms code gets to that point in the webutil.pll. So we never even get to the database.
Our next step, is to try to recreate the process solely in PL/SQL without webutil.pll, but the code in there is pretty extensive, and teasing out only the pieces we'll need is pretty tricky. -
Can we express batch relationship structure in XML in the database table
Hi
please help me ..
i have a batch XML batch structure ...can we express batch relationship structure in XML in tha database table?
yes..then how?
Thanks
Amu
Edited by: amu_2007 on Mar 25, 2010 6:57 PM
Edited by: amu_2007 on Mar 25, 2010 7:03 PMBut what is the problem with the initial solution given that split the XML into the data?
I mean you could do something like this?
SQL> create table batch (customer VARCHAR2(10)
2 ,cust_name VARCHAR2(10)
3 ,cust_type VARCHAR2(10)
4 )
5 /
Table created.
SQL>
SQL> create table section (customer VARCHAR2(10)
2 ,sect_name VARCHAR2(10)
3 ,sect_depend VARCHAR2(10)
4 )
5 /
Table created.
SQL> create table job_sections (customer VARCHAR2(10)
2 ,sect_name VARCHAR2(10)
3 ,job_sect_name VARCHAR2(10)
4 ,job_sect_depend VARCHAR2(10)
5 )
6 /
Table created.
SQL> create table job (customer VARCHAR2(10)
2 ,sect_name VARCHAR2(10)
3 ,job_sect_name VARCHAR2(10)
4 ,job_type VARCHAR2(10)
5 ,job_sub_type VARCHAR2(10)
6 ,job_depend VARCHAR2(10)
7 )
8 /
Table created.
SQL>
SQL>
SQL> insert all
2 when batch_rn = 1 then
3 into batch (customer, cust_name, cust_type) values (customer, cust_name, cust_type)
4 when section_rn = 1 then
5 into section (customer, sect_name, sect_depend) values (customer, sect_name, sect_dependency)
6 when job_sections_rn = 1 then
7 into job_sections (customer, sect_name, job_sect_name, job_sect_depend) values (customer, sect_name, job_sect_name, job_sect_dependency)
8 when 1=1 then
9 into job (customer, sect_name, job_sect_name, job_type, job_sub_type, job_depend) values (customer, sect_name, job_sect_name, job_type, jo
10 --
11 WITH t as (select XMLTYPE('
12 <BATCH customer="ABC" name="ABC1" type="ABC_TYPE">
13 <BATCH_SECTIONS>
14 <SECTION name="X" dependency="NULL">
15 <JOB_SECTIONS name="JOB1" dependency="NULL" >
16 <JOBS>
17 <JOB type="X" sub_type="xx" dependency="NULL" />
18 <JOB type="X" sub_type="yy" dependency="NULL" />
19 <JOB type="X" sub_type="zz" dependency="NULL" />
20 </JOBS>
21 </JOB_SECTIONS>
22 </SECTION>
23 <SECTION name="Y" dependency="X">
24 <JOB_SECTIONS name="JOB2" dependency="X" >
25 <JOBS>
26 <JOB type="Y" sub_type="xx" dependency="X" />
27 <JOB type="Y" sub_type="yy" dependency="X" />
28 <JOB type="Y" sub_type="zz" dependency="X" />
29 </JOBS>
30 </JOB_SECTIONS>
31 </SECTION>
32 <SECTION name="Z" dependency="Y">
33 <JOB_SECTIONS name="JOB3" dependency="NULL" >
34 <JOBS>
35 <JOB type="....." sub_type="...." dependency="NULL" />
36 </JOBS>
37 </JOB_SECTIONS>
38 <JOB_SECTIONS name="JOB4" dependency="NULL">
39 <JOBS>
40 <JOB type="...." sub_type="...." dependency="NULL" />
41 </JOBS>
42 </JOB_SECTIONS>
43 </SECTION>
44 </BATCH_SECTIONS>
45 </BATCH>
46 ') as xml from dual)
47 --
48 -- END OF TEST DATA
49 --
50 ,flat as (select a.customer, a.cust_name, a.cust_type
51 ,b.sect_name, NULLIF(b.sect_dependency,'NULL') as sect_dependency
52 ,c.job_sect_name, NULLIF(c.job_sect_dependency,'NULL') as job_sect_dependency
53 ,d.job_type, d.job_sub_type, NULLIF(d.job_dependency,'NULL') as job_dependency
54 from t
55 ,XMLTABLE('/BATCH'
56 PASSING t.xml
57 COLUMNS customer VARCHAR2(10) PATH '/BATCH/@customer'
58 ,cust_name VARCHAR2(10) PATH '/BATCH/@name'
59 ,cust_type VARCHAR2(10) PATH '/BATCH/@type'
60 ,bat_sections XMLTYPE PATH '/BATCH/BATCH_SECTIONS'
61 ) a
62 ,XMLTABLE('/BATCH_SECTIONS/SECTION'
63 PASSING a.bat_sections
64 COLUMNS sect_name VARCHAR2(10) PATH '/SECTION/@name'
65 ,sect_dependency VARCHAR2(10) PATH '/SECTION/@dependency'
66 ,section XMLTYPE PATH '/SECTION'
67 ) b
68 ,XMLTABLE('/SECTION/JOB_SECTIONS'
69 PASSING b.section
70 COLUMNS job_sect_name VARCHAR2(10) PATH '/JOB_SECTIONS/@name'
71 ,job_sect_dependency VARCHAR2(10) PATH '/JOB_SECTIONS/@dependency'
72 ,job_sections XMLTYPE PATH '/JOB_SECTIONS'
73 ) c
74 ,XMLTABLE('/JOB_SECTIONS/JOBS/JOB'
75 PASSING c.job_sections
76 COLUMNS job_type VARCHAR2(10) PATH '/JOB/@type'
77 ,job_sub_type VARCHAR2(10) PATH '/JOB/@sub_type'
78 ,job_dependency VARCHAR2(10) PATH '/JOB/@dependency'
79 ) d
80 )
81 --
82 select customer, cust_name, cust_type, sect_name, sect_dependency, job_sect_name, job_sect_dependency, job_type, job_sub_type, job_dependency
83 ,row_number() over (partition by customer order by 1) as batch_rn
84 ,row_number() over (partition by customer, sect_name order by 1) as section_rn
85 ,row_number() over (partition by customer, sect_name, job_sect_name order by 1) as job_sections_rn
86 from flat
87 /
16 rows created.
SQL> select * from batch;
CUSTOMER CUST_NAME CUST_TYPE
ABC ABC1 ABC_TYPE
SQL> select * from section;
CUSTOMER SECT_NAME SECT_DEPEN
ABC X
ABC Y X
ABC Z Y
SQL> select * from job_sections;
CUSTOMER SECT_NAME JOB_SECT_N JOB_SECT_D
ABC X JOB1
ABC Y JOB2 X
ABC Z JOB3
ABC Z JOB4
SQL> select * from job;
CUSTOMER SECT_NAME JOB_SECT_N JOB_TYPE JOB_SUB_TY JOB_DEPEND
ABC X JOB1 X xx
ABC X JOB1 X yy
ABC X JOB1 X zz
ABC Y JOB2 Y xx X
ABC Y JOB2 Y yy X
ABC Y JOB2 Y zz X
ABC Z JOB3 ..... ....
ABC Z JOB4 .... ....
8 rows selected.
SQL>But it would depend what you are actually after in terms of primary keys, and table relationships etc.
Let me put this simply for you...
h1. IF YOU DON'T DEMONSTRATE TO US WHAT OUTPUT YOU REQUIRE, WE CAN'T GIVE YOU AN ANSWER -
How to import an .csv file into the database?
and can we code the program in JSP to import the.csv file into the database.
It is better to use Java class to read the CSV file and store the contents in the database.
You can use JSP to upload the CSV file to the server if you want, but don't use it to perform database operations.
JSPs are good for displaying information on the front-end, and for displaying HTML forms, there are other technologies more suitable for the middle layer, back end and the database layer.
So break you application into
1) Front end - JSPs to display input html forms and to display data retrieved from the database.
2) Middle layer - Servlets and JavaBeans to interact with JSPs. The code that reads the CSV file to parse it's contents should be a Java Class in the middle layer. It makes use of Java File I/O
3) Database layer - Connects to the database using JDBC (Java Database Connectivity), and then writes to the database with SQL insert statements.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Keeping the above concepts in mind, first build a simple JSP and get it to work,
then research on Google , for Java File I/O , discover how to read a file,
Then search on how to readh a CSV file using Java.
After researching you should be able to read the CSV file line by line and store each line inside a Collection.
Then research on Google, on how to write to the database using JDBC
Write a simple program that inserts something to a dummy table in the database.
Then, read the data stored in the Collection, and write insert statements for each records in the collection. -
Loading a .wft file into the database
I have saved my workflow process into a .wft file. I would like to send this file to another person for them to load the process etc into their database. If I open the file, copy the contents of the file (looks like it is some script) into a word document and they then paste those contents into notepad and save the notepad as a .wft file and then upload into the database would this work out? The reason I am asking this question is because, I cannot send them the attachment, but need to write up the contents in a word document.
ThanksYes you can do that.
-
Can not login into the database 9i
I use WarehouseBuilder 9i's repository assistant to create new repository on a host.While the database is oracle 9i release 2 , the sysdba's name/password can't login into the database.But if the database is oracle 8.1.7 ,the sysdba's name/password can login.Why?
If the oracle 9i doesn't support WarehouseBuilder 9i ?This is well known bug in OWH 9i.
The thing is:
1. Repository Assistant need to login under SYS and only SYS
2. SYS are allowed to login to Oracle 9i only AS SYSDBA
3. ... but Repository Assistant CANNOT correctly login by "SYS AS SYSDBA"
Solution:
1. Set Oracle 9i init parameter O7_DICTIONARY_ACCESSIBILITY=TRUE and restart database instance. This allow you to login as SYS (without SYSDBA) to Oracle 9i. -
Get the data from excel and insert into the database
I want to read the data from excel file, get the data from excel and insert into the database.
You can use the Apache POI HSSF API to read data from Excel files and you can use the Sun JDBC API to insert data in database.
This has nothing to do with JSP/JSTL. -
Loading class oracle/jpub/runtime/dbws/DbwsProxy into the database
I am trying to create a Database Web Services call-out in PL/SQL, however, encountered error "ORA-29540: class oracle/jpub/runtime/dbws/DbwsProxy does not exist". I followed some steps to load utl_dbws.jar, utl_dbws_jserver.jar and dbwsclient.jar into the database, but still getting the same error saying DbwsProxy class does not exist. This is very frustrating and I do not know how to fix this. I tried to just load DbwsProxy.class into the database and it executed successfully, however, the database is still complaining that oracle/jpub/runtime/dbws/DbwsProxy does not exist. Does anyone has any idea what's going on? Thanks much. I am cracking my brain out here.
This is the error message I received when loading:
The following operations failed
class java/lang/NumberFormatException: creation (createFailed)
class java/lang/Number: creation (createFailed)
class java/lang/Object: creation (createFailed)
class java/lang/String: creation (createFailed)
class java/lang/Long: creation (createFailed)
exiting : Failures occurred during processing
This is the error message I received in the database after loading dbwsclient.jar:
ERROR at line 1:
ORA-29540: class oracle/jpub/runtime/dbws/DbwsProxy does not exist
ORA-06512: at "SYS.UTL_DBWS", line 135
ORA-06512: at "SYS.UTL_DBWS", line 132
ORA-06512: at "MICHELLE.MICH", line 8
ORA-06512: at line 1
So that class is still missing. You were suspecting that this class is not loaded successfully into the database? Is it possible for me to just load that particular class into the database?
Thanks. -
Insert multiple rows of records into the database
The codes below allow me to insert a row of record into the database. How would I changed these to insert multiple rows at once? Please help!
String sql = "INSERT INTO EMPLOYEES" +
"(First_Name, Last_Name, Title, Phone) " +
" VALUES " +
PreparedStatement statement = conn.prepareStatement(sql);
statement.setObject (1, First_Name);
statement.setObject (2, Last_Name);
statement.setObject (3, Title);
statement.setObject (4, Phone);
boolean returnValue = statement.execute();Hi mystiqueX,
As wmolosho has suggested in his answer to this very same question that you also posted to the JavaServer Pages forum, you can create a batch of inserts and perform them using the "executeBatch()" method. I will use Craig's sample code to demonstrate:
(Note that this code is untested!)
conn.setAutoCommit(false);
PreparedStatement statement = conn.prepareStatement(sql);
// assume you have an array of objects here
for (int i = 0; i < data.length; i++) {
statement.setString(1, data<i>.getFirstName());
statement.setString(2, data<i>.getLastName());
statement.setString(3, data<i>.getTitle());
statement.setString(4, data<i>.getPhone());
statement.addBatch();
statement.executeBatch();
conn.commit();If you are not familiar with it, allow me to suggest looking at the Making Batch Updates lesson on the Java Tutorial.
Hope it helps.
Good Luck,
Avi. -
How to Save the multiple selection check box values into the database
i have the multiple selection check box implemented in UI through drop down list,i can choose the desired values from the drop down through checkbox, but i m unable to store these values and commit the values into the database all at a time.
You can access the values using listbinding and can then store them as a string by using a delimiter.
-
Store APEX_ITEM.RADIOGROUP value into the database!
Hi All,
I am using the following query to display questions from a table. Does anyone know how we can insert the value of APEX_ITEM.RADIOGROUP(if it is a radiogroup with static LOV ie. Static2: very poor;1,good;2,very good;3,excellent;4) into the database.
select question_id,
question_desc,
APEX_ITEM.RADIOGROUP(1) as rating
from table_name
Thanks,
Parveen SehrawatAlso tried it this way:
function reviewerID() {
var reviewer =html_RadioValue('f01');
if (reviewer == 1){
html_GetElement('P1_CUSTOMER_ID').value = 1;
if (reviewer == 2){
html_GetElement('P1_CUSTOMER_ID').value = 2;
if (reviewer == 3){
html_GetElement('P1_CUSTOMER_ID').value = 3;
if (reviewer == 4){
html_GetElement('P1_CUSTOMER_ID').value = 4;
if (reviewer == 5){
html_GetElement('P1_CUSTOMER_ID').value = 5;
its clumbsy but i thought it would do the job... am still gettin the same error trying it this way though....
l_This has no properties
l_Selects = l_This.getElementsByTagName('SELECT');
Help from anyone much appreciated!! -
Why does not the data get saved into the Database
Please check if there is any thing wrong with my code here. Why cant i save the data in to my database. when i used the same things in other places it works.
guys i have copied a portion of the code here. right now i have commented few areas to not give me any errors on the whole program
Please check why cant i save the data into the database.
i have created a seperate class for database connection Utilities
void saveData()
//Utilities ut = new Utilities();
//connection = ut.getConnection();
//ResultSet resultSet;
// JourneyID = ut.getResults(qryJourneyID);
strJourneyID = txtJourneyID.getText();
System.out.println("++++++++++++++++++++++++"+strJourneyID);
strVehicleID = (String)comboVehicleID.getSelectedItem();
System.out.println("++++++++++++++++++++++++"+strVehicleID);
strDriverID = (String)comboDvrID.getSelectedItem();
System.out.println("++++++++++++++++++++++++"+strDriverID);
strStartDateTime = txtDateTime.getText();
System.out.println("++++++++++++++++++++++++"+strStartDateTime);
int a = JOptionPane.showConfirmDialog (null, "Are u sure you want to save the changes?", "WARNING!", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (a == 0)
if(NEW)// new is a boolean value
//ADDING NEW DATA STATMENT
System.out.println("INSERTING NEW ROW IN THE TABLE...");
try
String insert ="INSERT INTO Job VALUES (" + "'" + strJourneyID + "'"+
", '"+ strVehicleID + "',"
+"'"+ strDriverID +"',"
+ "'"+ strStartDateTime +"')";
System.out.println("STATEMENT IS " + insert);
// InsertStmt = connection.createStatement();
// InsertStmt.executeUpdate(insert);
JOptionPane.showMessageDialog(null, "You data has been successfully saved.","TIS: Operation completed", JOptionPane.INFORMATION_MESSAGE);
catch (Exception e)
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Problem encountered while adding new data");
else
JOptionPane.showMessageDialog(null, "it is supposed to save data");
/*try
String ChangeRecord = "UPDATE Job SET " +
"JourneyID = '" + strJourneyID+ "'"+
"VehicleID = '" + strVehicleID+"',"+
"DriverID = '"+strDriverID+"'," +
"StartDateTime='" + strStartDateTime+ "'";//syntax error???
System.out.println(""+ ChangeRecord);
UpdateStmt = connection.createStatement();//just added
UpdateStmt.executeUpdate(ChangeRecord);
JOptionPane.showMessageDialog(null, "You data has been successfully saved.","TIS: Operation completed", JOptionPane.INFORMATION_MESSAGE);
catch (Exception change_exception)
change_exception.printStackTrace();
JOptionPane.showMessageDialog (null, "Problem encountered while updating","TIS: Problem encountered",JOptionPane.ERROR_MESSAGE);
else
JOptionPane.showMessageDialog(null, "You chose to cancel the operation","Operation cancelled", JOptionPane.INFORMATION_MESSAGE);
}Yes you have commented all the code that update the
database so how can it update the database.
By the way for inserting dont use Statement use
PrepairedStatement
by the way next time please post codes in code tagsMan i have commented it becaues it if i dont comment it givens me errors. like cannot find variable and i dont understand how to use the code button. whereever i click the code button it displays the at the end of the code! what to do?
connection = ut.getConnection();
ResultSet resultSet;
UpdateStmt = connection.createStatement();
UpdateStmt = connection.createStatement();
UpdateStmt.executeUpdate(ChangeRecord);
please check it once again
void saveData()
Utilities ut = new Utilities();
connection = ut.getConnection();
ResultSet resultSet;
// JourneyID = ut.getResults(qryJourneyID);
strJourneyID = txtJourneyID.getText();
System.out.println("++++++++++++++++++++++++"+strJourneyID);
strVehicleID = (String)comboVehicleID.getSelectedItem();
System.out.println("++++++++++++++++++++++++"+strVehicleID);
strDriverID = (String)comboDvrID.getSelectedItem();
System.out.println("++++++++++++++++++++++++"+strDriverID);
strStartDateTime = txtDateTime.getText();
System.out.println("++++++++++++++++++++++++"+strStartDateTime);
int a = JOptionPane.showConfirmDialog (null, "Are u sure you want to save the changes?", "WARNING!", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (a == 0)
if(NEW)
//ADDING NEW DATA STATMENT
System.out.println("INSERTING NEW ROW IN THE TABLE...");
try
String insert ="INSERT INTO Job VALUES (" + "'" + strJourneyID + "'"+
", '"+ strVehicleID + "',"
+"'"+ strDriverID +"',"
+ "'"+ strStartDateTime +"')";
System.out.println("STATEMENT IS " + insert);
// InsertStmt = connection.createStatement();
// InsertStmt.executeUpdate(insert);
JOptionPane.showMessageDialog(null, "You data has been successfully saved.","TIS: Operation completed", JOptionPane.INFORMATION_MESSAGE);
catch (Exception e)
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Problem encountered while adding new data");
else
JOptionPane.showMessageDialog(null, "it is supposed to save data");
try
String ChangeRecord = "UPDATE Job SET " +
"JourneyID = '" + strJourneyID+ "'"+
"VehicleID = '" + strVehicleID+"',"+
"DriverID = '"+strDriverID+"'," +
"StartDateTime='" + strStartDateTime+ "'";//syntax error???
System.out.println(""+ ChangeRecord);
UpdateStmt = connection.createStatement();//just added
UpdateStmt.executeUpdate(ChangeRecord);
JOptionPane.showMessageDialog(null, "You data has been successfully saved.","TIS: Operation completed", JOptionPane.INFORMATION_MESSAGE);
catch (Exception change_exception)
change_exception.printStackTrace();
JOptionPane.showMessageDialog (null, "Problem encountered while updating","TIS: Problem encountered",JOptionPane.ERROR_MESSAGE);
else
JOptionPane.showMessageDialog(null, "You chose to cancel the operation","Operation cancelled", JOptionPane.INFORMATION_MESSAGE);
}
Maybe you are looking for
-
Help with provide statement In ABAP HR
Hi to all experts, My requirement is to display locked records with start date and end date But the problem when i select the period as current month im getting the start date of the current month and enddate of the current month PROVIDE * FROM p000
-
Line item report on Statistical WBS element.
Hi All, I need to extract Line report on statistical WBS element. I tried CJI3 and end up with the message No costs, revenues or finances were selected. can some one help me on this. Thanks and Regards, Vinod
-
Libretto U100 Keyboard - need to replace it - important!
Hi does anyone where i can get a replacement Keyboard for the Toshiba Libretto U100 Model No: PLU10E-009017EN. My current one has a key missing on it and some of the keys stopped working due to drink being spilt over it by kids. An external Keyboard
-
my onkyo dvd player doesn't display title/artist/album info when I burn an mp3 cd from Itunes. What do I need to do ?
-
Unable to open Motion inside FCPX
I just purchased an iMac and installed Final Cut pro X , Motion 5, Compressor as well as a third party plug-in (Red Giants Magic Bullet Looks) but I am unable to access Motion or Magic Bullet Looks through the host program (Final Cut). Am I suppose t