Question re use of sequence in INSERT statement
Hi
I a having a problem inserting data into a table. I have created a sequence....
CREATE SEQUENCE ag_in_target_seq
INCREMENT BY 1
START WITH 1
;and Im trying to use it to insert an incrementing ID value into a column for newly created table. Im getting an error message with regard to the sequence.
"The specified sequence number (CURRVAL or NEXTVAL) is inappropriate here in the statement."
I've just started looking at sequences but not sure of my logic or syntax. (bit of a noob). If someone could point me in the right direction it would be much appreciated. Thanks a mil.
INSERT INTO AGENTSINFOTARGET
SELECT
a.code_name,
i.information_id,
i.gleaned_date,
t.first_name,
t.last_name,
l.description,
ag_in_target_seq.nextval
FROM
agents a
INNER JOIN
information i ON
a.agent_id=i.agent_id
INNER JOIN
targets t ON
i.target_id=t.target_id
INNER JOIN
locations l on
t.location_id=l.location_id
ORDER BY
a.code_name desc
;
Hi Sanjay
Thanks for taking an interest, here is the full error message
Error at Command Line:9 Column:28
Error report:
SQL Error: ORA-02287: sequence number not allowed here
02287. 00000 - "sequence number not allowed here"
*Cause: The specified sequence number (CURRVAL or NEXTVAL) is inappropriate
here in the statement.
*Action: Remove the sequence number.
Similar Messages
-
Use NEXTVAL in an insert statement Part II
db - 10g
I am asking this question out of curiosity.
I posted a question and recieved a successful answer at the following address on this forum;
Use NEXTVAL in an insert statement
The following insert statement uses a sequence to create an arbitrary number for each null record. The problem is, the sequence is firing regardless of the condition being true or false (but it is working in that it only inserts values when the condition is true). The result is the sequence appears to increment each time it loops through the cursor and so the first arbitrary number to be inserted is not 1001 but some other higher number.
INSERT INTO psp_trees
( plot_id
, tree_name
, species_code)
VALUES
( get_plot_id
, c1.treenum
, c1.species
) RETURNING tree_id INTO get_tree_id; I have gotten around the issue by removing the sequence from the insert statement and placing it outside the cursor loop as an update statement.
UPDATE psp_trees
SET tree_name = to_char(tree_arbitrary_name_seq.nextval)
WHERE tree_name IS NULL;Is there anyway to get the sequence to only fire in the insert statement when the condition is true.
This is the complete anonymous block for your reference;
DECLARE p_access_num NUMBER;
col_access_var VARCHAR2(30);
type number_ptb IS table OF VARCHAR2(4000);
p_access_nam number_ptb;
get_plot_measurement_id NUMBER;
update_plot_measurements VARCHAR2(4000);
get_tree_id NUMBER;
get_plot_id NUMBER;
BEGIN
p_access_num := 6;
p_access_nam := number_ptb();
p_access_nam.extend(7);
p_access_nam(1) := 535;
p_access_nam(2) := 548;
p_access_nam(3) := 898;
p_access_nam(4) := 544;
p_access_nam(5) := 551;
p_access_nam(6) := 724;
FOR loop_int IN 1 .. p_access_num
LOOP
col_access_var := p_access_nam(loop_int);
-- 1. Initiate insert process by getting PK from psp_plots.
SELECT plot_id INTO get_plot_id FROM psp_plots WHERE plot_name = col_access_var;
-- 2. Insert records into psp_plot_measurements and keep relationship with psp_plots with variable get_plot_id.
-- and get primary key value of psp_plot_measurements to insert into psp_tree_measurements during loop process.
INSERT INTO psp_plot_measurements (plot_id) VALUES (get_plot_id) RETURNING plot_measurement_id INTO get_plot_measurement_id;
-- 3. Update record created at point 2.
UPDATE psp_plot_measurements
SET measurement_date = (SELECT DISTINCT date_ FROM pspdata)
, codominant_height = (SELECT DISTINCT height_codom FROM pspdata)
, assessor = (SELECT DISTINCT assessor FROM pspdata)
WHERE plot_measurement_id = col_access_var
-- 4. Open cursor to insert rows one at a time and maintain relationships between related tables.
FOR c1 IN (SELECT treenum
, dbhob
, treecomments
, species
FROM pspdata
WHERE plotnumber = col_access_var
AND date_ IS NOT NULL)
LOOP
-- 5. Insert record into psp_trees
-- and get primary key value of psp_trees to insert into psp_tree_measurements.
INSERT INTO psp_trees
( plot_id
, tree_name
, species_code)
VALUES
( get_plot_id
, c1.treenum
--, NVL(c1.treenum , to_char(tree_arbitrary_name_seq.nextval))
--, (CASE WHEN c1.treenum IS NULL THEN to_char(tree_arbitrary_name_seq.nextval) ELSE c1.treenum END)
, c1.species
) RETURNING tree_id INTO get_tree_id;
-- 6. Insert records into psp_tree_measurements and keep relationship with psp_trees with variable get_tree_id.
INSERT INTO psp_tree_measurements
( plot_measurement_id
, tree_id
, dbhob
, comments
VALUES
( get_plot_measurement_id
, get_tree_id
, c1.dbhob
, c1.comment
END LOOP;
END LOOP;
-- 7. Update null columns with arbitrary number.
UPDATE psp_trees
SET tree_name = to_char(tree_arbitrary_name_seq.nextval)
WHERE tree_name IS NULL;
END;
/Edited by: benton on Sep 6, 2011 1:53 PMOr use a function (I'll use dbms_xml.getxml):
SQL> create sequence s_seq nocache
Sequence created.
SQL> select case when mod (level, 2) = 0
then extractvalue(dbms_xmlgen.getxmltype('select s_seq.nextval from dual'), '//text()')
else '0' end col1
from dual connect by level < 20
COL1
0
1
0
2
0
3
0
4
0
5
0
6
0
7
0
8
0
9
0
19 rows selected.
SQL> select sequence_name, last_number from user_sequences where sequence_name = 'S_SEQ'
SEQUENCE_NAME LAST_NUMBER
S_SEQ 10
1 row selected. -
Using System::ErrorDescription in Insert statement
Hello,
I want to insert System::ErrorDescription to store the error in the customized log table. When I use the following statement, it does not insert anything. What am i doing wrong. Please advice.
create table dbo.load_err(load_err_id integer(PK),load_err_Dtl,loadtime)
INSERT INTO dbo.LOAD_ERR (LOAD_ERR_ID,
LOAD_ERR_DTL,
loadtime)
VALUES (NEXT VALUE FOR dbo.LOAD_ERR_SEQ,
@[System::ErrorDescription] ,
getdate())
I see the row inserted but nothing in the Load_ERR_DTL column.Where are you using the insert statement? The ErrorDescription variable is only available inside OnError,OnWarning and OnInformation event handlers
http://msdn.microsoft.com/en-IN/library/ms141788.aspx
Also you need to use insert statement as below
INSERT INTO dbo.LOAD_ERR (LOAD_ERR_ID,
LOAD_ERR_DTL,
loadtime)
VALUES (NEXT VALUE FOR dbo.LOAD_ERR_SEQ,
getdate())
and map parameter0 to @[System::ErrorDescription] in parameters tab
another way is to set SQLSourceType
as Variable and set a variable for the query with below expression as
"INSERT INTO dbo.LOAD_ERR (LOAD_ERR_ID,
LOAD_ERR_DTL,
loadtime)
VALUES (NEXT VALUE FOR dbo.LOAD_ERR_SEQ,'" +
@[System::ErrorDescription] + "',
getdate())"
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Using package call in insert statement.
insert into
as_portal_credentials_test
values('id', 'key','expid',UTL_RAW.CAST_TO_RAW('zTMwv2.[[?~d'))Where are you using the insert statement? The ErrorDescription variable is only available inside OnError,OnWarning and OnInformation event handlers
http://msdn.microsoft.com/en-IN/library/ms141788.aspx
Also you need to use insert statement as below
INSERT INTO dbo.LOAD_ERR (LOAD_ERR_ID,
LOAD_ERR_DTL,
loadtime)
VALUES (NEXT VALUE FOR dbo.LOAD_ERR_SEQ,
getdate())
and map parameter0 to @[System::ErrorDescription] in parameters tab
another way is to set SQLSourceType
as Variable and set a variable for the query with below expression as
"INSERT INTO dbo.LOAD_ERR (LOAD_ERR_ID,
LOAD_ERR_DTL,
loadtime)
VALUES (NEXT VALUE FOR dbo.LOAD_ERR_SEQ,'" +
@[System::ErrorDescription] + "',
getdate())"
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Using Special characters in Insert statement
Hi All,
I want to insert special characters in my table. Here is my query
insert into COM_TAB(TAB_COMMENTS) VALUES('ADAM'S FARM & FARM-GANG APPLE GOOGLE') .Please help.Also tel me is there any method to handle special characters like using ascci values for itPut the & and ' as below
create table com_tab(tab_comments varchar2(128));
insert into COM_TAB(TAB_COMMENTS) VALUES('ADAM''S FARM ' || '&' || ' FARM-GANG APPLE GOOGLE')
select * from com_tab
TAB_COMMENTS
ADAM'S FARM & FARM-GANG APPLE GOOGLE -
Question about use of get_variable and if statement
Hi!
I have the following code in an RTF file.
<?for-each@section:G_NYU_TSRSLT_HDR?>
Display <?ACAD_CAREER?>
<?xdoxslt:set_variable($_XDOCTX, 'acad_career_in', ACAD_CAREER)?>
<?if:xdoxslt:get_variable($_XDOCTX, 'acad_career_in')='UGRD' ?> UGRD <?end if?>
<?if:xdoxslt:get_variable($_XDOCTX, 'acad_career_in')='GRAD' ?> GRAD <?end if?>
<?end for?>
I believe it is looping through two rows. The first row has ACAD_CAREER = 'UGRD' and the second row has ACAD_CAREER = 'GRAD'
The output is:
Display UGRD
UGRD
Display GRAD
UGRD
GRAD
For some reason, it appears like the second time the if UGRD statement is run, it still thinks the result is true.
Any ideas?
Thanks!Hi, Sent the email. Thanks for your help!!! The code which is till the problem is (all code is in form fields in the RTF):
<?for-each@section:G_NYU_TSRSLT_HDR?>
<?xdoxslt:set_variable($_XDOCTX, 'acad_career_in', ACAD_CAREER)?>
Display <?ACAD_CAREER?>
<?if:xdoxslt:get_variable($_XDOCTX, 'acad_career_in')='UGRD' ?> UGRD <?end if?>
<?if:xdoxslt:get_variable($_XDOCTX, 'acad_career_in')='GRAD' ?> GRAD <?end if?>
<?end for-each@section?>
The output is:
Display UGRD
UGRD
<on a new page>
Display GRAD
UGRD
GRAD -
Using sqlerrm in insert statement in 10g
Hi,
I do not have 10g to test the following snippet, which tries to use sqlerrm in an insert statement:
-- start testcase
drop table tbl;
drop table err;
create table tbl (x number);
create table err (a number, b varchar2(4000));
declare
n_tmp tbl.x%type;
begin
select x into n_tmp from tbl;
exception
when others then
-- the line below works in 9i
-- dbms_output.put_line('Sqlerrm: '||sqlerrm);
-- but the insert statement doesn't work in 9i, how about 10g ?
insert into err(a,b) values (1,sqlerrm);
commit;
end;
declare
n_tmp tbl.x%type;
begin
select x into n_tmp from tbl;
exception
when others then
-- the line below works in 9i
-- dbms_output.put_line('Sqlerrm: '||sqlerrm);
-- the insert statement works in 9iR2 but the error message is
-- not the one sought, how about 10g ?
insert into err(a,b) values (1,sys.standard.sqlerrm);
commit;
end;
/Can someone test it on any release/edition of 10g please ?
The tests on 9iR2 below behave predictably:
SQL>
SQL> @ver
BANNER
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
PL/SQL Release 9.2.0.8.0 - Production
CORE 9.2.0.8.0 Production
TNS for Solaris: Version 9.2.0.8.0 - Production
NLSRTL Version 9.2.0.8.0 - Production
SQL>
SQL>
SQL> -- start testcase
SQL> drop table tbl;
Table dropped.
SQL> drop table err;
Table dropped.
SQL>
SQL> create table tbl (x number);
Table created.
SQL> create table err (a number, b varchar2(4000));
Table created.
SQL>
SQL> declare
2 n_tmp tbl.x%type;
3 begin
4 select x into n_tmp from tbl;
5 exception
6 when others then
7 -- the line below works in 9i
8 -- dbms_output.put_line('Sqlerrm: '||sqlerrm);
9 -- but the insert statement doesn't work in 9i, how about 10g ?
10 insert into err(a,b) values (1,sqlerrm);
11 commit;
12 end;
13 /
insert into err(a,b) values (1,sqlerrm);
ERROR at line 10:
ORA-06550: line 10, column 36:
PL/SQL: ORA-00984: column not allowed here
ORA-06550: line 10, column 5:
PL/SQL: SQL Statement ignored
SQL>
SQL> --
SQL> declare
2 n_tmp tbl.x%type;
3 begin
4 select x into n_tmp from tbl;
5 exception
6 when others then
7 -- the line below works in 9i
8 -- dbms_output.put_line('Sqlerrm: '||sqlerrm);
9 -- the insert statement works in 9iR2 but the error message is
10 -- not the one sought, how about 10g ?
11 insert into err(a,b) values (1,sys.standard.sqlerrm);
12 commit;
13 end;
14 /
PL/SQL procedure successfully completed.
SQL>
SQL> select * from err;
A B
1 ORA-0000: normal, successful completion
SQL>
SQL>The behavior of the second pl/sql block was mentioned by Nicolas:
Re: INSERT INTO ..VALUES (SQLERRM, SQLCODE, SYSDATE) doesn't work?
Is there any change in 10g ?
Thanks in advance,
pratz
(Sorry, the hyperlink is getting modified automatically; remove the backslash ("\") immediately before the ampersand ("&") character.)
Message was edited by:
pratzSame in 10.2.0.3.0
SQL*Plus: Release 10.1.0.4.2 - Production on Thu Jan 24 11:55:53 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> drop table tbl;
Table dropped.
SQL>
SQL> drop table err;
Table dropped.
SQL>
SQL> create table tbl (x number);
Table created.
SQL>
SQL> create table err (a number, b varchar2(4000));
Table created.
SQL> declare
2 n_tmp tbl.x%type;
3 begin select x into n_tmp from tbl;
4 exception when others then
5 -- the line below works in 9i
6 --dbms_output.put_line('Sqlerrm: '||sqlerrm);
7 -- but the insert statement doesn't work in 9i, how about 10g ?
8 insert into err(a,b) values (1,sqlerrm);
9 commit;
10 end;
11 /
insert into err(a,b) values (1,sqlerrm);
ERROR at line 8:
ORA-06550: line 8, column 32:
PL/SQL: ORA-00984: column not allowed here
ORA-06550: line 8, column 1:
PL/SQL: SQL Statement ignored
SQL> declare
2 n_tmp tbl.x%type;
3 begin
4 select x into n_tmp from tbl;
5 exception when others then
6 -- the line below works in 9i
7 --dbms_output.put_line('Sqlerrm: '||sqlerrm);
8 -- the insert statement works in 9iR2 but the error message is -- not the one sought, how a
bout 10g ? i
9 insert into err(a,b) values (1,sys.standard.sqlerrm);
10 commit;
11 end;
12 /
PL/SQL procedure successfully completed.
SQL> select * from err;
A
B
1
ORA-0000: normal, successful completion
SQL> -
Hi,
I'm using a sequence in INSERT ALL statement. I want to insert multiple rows using a sequence number which will be generating the unique values for my table. But as far as i know, Oracle treats all occurances of a seq.nextval as a single reference and all of them retains the same value and not different one. My query is as below.
insert all
into t1(c1, c2) values (seq_1.nextval, 'A')
into t1(c1, c2) values (seq_1.nextval, 'B')
select * from dual;
select * from t1;
C1 C2
8 A
8 B
Can some one tell me how can i have different values for each row in insert all statement?Create a function:
SQL> create or replace
2 function get_seq_1
3 return number
4 is
5 v_ret number;
6 begin
7 select seq_1.nextval into v_ret from dual;
8 return v_ret;
9 end;
10 /
Function created.
SQL> insert all
2 into t1(c1, c2) values (seq_1.nextval, 'A')
3 into t1(c1, c2) values (seq_1.nextval, 'B')
4 select * from dual;
2 rows created.
SQL>
SQL> select * from t1;
C1 C2
1 A
1 B
SQL> insert all
2 into t1(c1, c2) values (get_seq_1, 'A')
3 into t1(c1, c2) values (get_seq_1, 'A')
4 select * from dual;
2 rows created.
SQL> select * from t1;
C1 C2
1 A
1 B
2 A
3 A
SQL> SY. -
Create multiple Insert statements from multiselect list
I want to thank everyone in advance for the help on this one.
I have a multiselect list that I would like to use to create multiple Insert statements. I would like to then take those statements and execute them against the database, thus inserting the records. My thoughts are below;
1. Customer selects multiple items in the list
2. Clicks the submit button
3. onclick event walks through the string created by the multiselect list and creates the Insert statements by walking through an array of the values.
4. the Insert statements get executed against the database
5. page redirects to the proper page after the process is done.
I actually have already created a javascript function that will use the split command on the string to create an array. I then get the length of the array and walk through a loop creating the sql statements. I am not sure what to do from here. How can I get the sql to execute.
I am not wed to this approach. If there is a better idea out there please do not hesitate to share it with me. I am relatively new to APEX and have not done much work in pl/sql or javascript. But I learn fast, so don’t hold back.
Thanks again and please let me know what questions you have for me.
Derek.I setup the demo app on apex.oracle.com:
http://apex.oracle.com/pls/apex/f?p=26255:3
Login as demo / demo
Go to the "products" tab. There is a Test region with a multiselect list. It shows product names (with product id's) from the demo_product_info table.
When you select multiple things from the list and click apply, it uses the following procedure to simply insert a new record for each into the product table. It increments the product_id by 1000 and prepends "DUPLICATE " to the product_name:
declare
cursor c_products is
select product_name, product_id
from demo_product_info
where instr(':' || :P3_X || ':', ':' || product_id || ':') >= 1
order by 1
begin
for r_product in c_products loop
insert into demo_product_info (product_id, product_name)
values (r_product.product_id + 1000, 'DUPLICATE ' || r_product.product_name);
end loop;
end;
You can see that is working by using it on the duplicate entries themselves.
-Richard -
INSERT statement in Java and MS Access
Hi all,
can anyone please tell me how to insert data to an MS Access table using JSP i tried INSERT statement of java but it is getting errors saying INSERT statement is wrong. I have no idea about MS access insert statement. i am totally tired of this. Please someone help me.Hello,
MS Sql can cause problems where it goes off standard, however I dont think insert is any different.
INSERT INTO table_name (column1, column2) VALUES (variable1, variable2)
Make sure your table and column names are exactly right, Java is case sensitive, so make sure the case is correct also.
The other common error is if you have a required field in the database that is not populated by your program, so, if for instance there was a column3 in the table for the above example, which was a required field, the sql would fail as there is no data being entered for column3. -
ROWCOUNT in BULK Insert Statement
Hi,
I'm using in a BULK INSERT statement in a PL/SQL procedure and after execution of the SQL statement,I need to capture the row count.
Same is the case for UPDATE.
The Example code is as mentioned below:
INSERT INTO TBL1
(SELECT VAL1,VAL2 FROM TBL2)
No. of rows inserted needs to be retrieved after execution of this SQL.
Please let me know if there is any way to do it.
Thanks.SQL> create table emp as select * from scott.emp where 1 = 0 ;
Table created.
SQL> set serveroutput on
SQL> begin
2 insert into emp select * from scott.emp ;
3 dbms_output.put_line('Count='||SQL%RowCount) ;
4 end ;
5 /
Count=14
PL/SQL procedure successfully completed.
SQL> -
Connecting to DB2 Database using JDBC for select/Insert
Hi,
I am trying to connect to an DB2 Database using JDBC adapter, I have build an UDF for the same.
The UDF will try to query the database in the form of Select and INSERT.I am using the LOOKUP API provided by SAP.When I try to execute the UDF I have received the following error.can any of you provide the solution for the error and also is it that the JDBC adapter has to be situated on Central Adapter engine to execute the API, can the JDBC adapter used for executing the INSERT statement.
Exception during processing the payload.Problem when calling an adapter by using communication channel JDBC_PIDB_Receiver_CC (Party: , Service: XIDB_BSRV, Object ID: 59f2d7694acc3e81840f89b0169d9323) XI AF API call failed. Module exception: (No information available). Cause Exception: (No information available).
com.sap.aii.mapping.lookup.LookupException: Problem when calling an adapter by using communication channel JDBC_PIDB_Receiver_CC (Party: , Service: XIDB_BSRV, Object ID: 59f2d7694acc3e81840f89b0169d9323) XI AF API call failed. Module exception: (No information available). Cause Exception: (No information available).
at com.sap.aii.ibrun.server.lookup.AdapterProxyLocal.execute(AdapterProxyLocal.java:131)
at com.sap.aii.ibrun.server.lookup.SystemAccessorInternal.execute(SystemAccessorInternal.java:68)
at com.sap.aii.ibrun.server.lookup.SystemAccessorHmiServer.process(SystemAccessorHmiServer.java:149)
at com.sap.aii.ibrun.server.lookup.SystemAccessorHmiServer.process(SystemAccessorHmiServer.java:77)
at com.sap.aii.utilxi.hmis.server.HmisServiceImpl.invokeMethod(HmisServiceImpl.java:169)
at com.sap.aii.utilxi.hmis.server.HmisServer.process(HmisServer.java:178)
at com.sap.aii.utilxi.hmis.web.HmisServletImpl.processRequestByHmiServer(HmisServletImpl.java:296)
at com.sap.aii.utilxi.hmis.web.HmisServletImpl.processRequestByHmiServer(HmisServletImpl.java:211)
at com.sap.aii.utilxi.hmis.web.workers.HmisInternalClient.doWork(HmisInternalClient.java:70)
at com.sap.aii.utilxi.hmis.web.HmisServletImpl.doWork(HmisServletImpl.java:496)
at com.sap.aii.utilxi.hmis.web.HmisServletImpl.doPost(HmisServletImpl.java:634)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:401)
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:386)
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:364)
at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:1039)
at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:265)
at com.sap.engine.services.httpserver.server.Client.handle(Client.java:95)
at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:175)
at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
at java.security.AccessController.doPrivileged(Native Method)
at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:102)
at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:172)
Root Cause:
com.sap.aii.af.service.api.AFException: XI AF API call failed. Module exception: (No information available). Cause Exception: (No information available).
at com.sap.aii.af.service.api.AdapterAccess.sendMsg(AdapterAccess.java:214)
at com.sap.aii.af.service.api.AdapterAccess.execute(AdapterAccess.java:283)
at com.sap.aii.ibrun.server.lookup.AdapterProxyLocal.execute(AdapterProxyLocal.java:123)
at com.sap.aii.ibrun.server.lookup.SystemAccessorInternal.execute(SystemAccessorInternal.java:68)
at com.sap.aii.ibrun.server.lookup.SystemAccessorHmiServer.process(SystemAccessorHmiServer.java:149)
at com.sap.aii.ibrun.server.lookup.SystemAccessorHmiServer.process(SystemAccessorHmiServer.java:77)
at com.sap.aii.utilxi.hmis.server.HmisServiceImpl.invokeMethod(HmisServiceImpl.java:169)
at com.sap.aii.utilxi.hmis.server.HmisServer.process(HmisServer.java:178)
at com.sap.aii.utilxi.hmis.web.HmisServletImpl.processRequestByHmiServer(HmisServletImpl.java:296)
at com.sap.aii.utilxi.hmis.web.HmisServletImpl.processRequestByHmiServer(HmisServletImpl.java:211)
at com.sap.aii.utilxi.hmis.web.workers.HmisInternalClient.doWork(HmisInternalClient.java:70)
at com.sap.aii.utilxi.hmis.web.HmisServletImpl.doWork(HmisServletImpl.java:496)
at com.sap.aii.utilxi.hmis.web.HmisServletImpl.doPost(HmisServletImpl.java:634)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:401)
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:386)
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:364)
at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:1039)
at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:265)
at com.sap.engine.services.httpserver.server.Client.handle(Client.java:95)
at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:175)
at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
at java.security.AccessController.doPrivileged(Native Method)
at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:102)
at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:172)
Thanks,
Kiran.Hi,
have you deployed the JDBC driver for your DB2 database in your XI system........if not, then ask your basis guys to find the weblog to deploy the JDBC driver in XI system and then deploy your DB2 database driver in your JDBC driver in XI system............
then again execute your scenario.
Regards,
Rajeev Gupta -
Using sequence in insert trigger?
Hi all,
I'm new to this forum, and for that matter, any forums related to computers.
I would appreciate it if anyone would give me some hinters.
I created a table with an ID column of type "Number." And I want to populate that column with a sequence number everytime I insert into that table.
I have a sequence named "sequence1_account."
Below is my insert trigger code:
create TRIGGER system.trigger1_account
BEFORE INSERT ON system.table_account
for each row
BEGIN
:new.id := sequence1_account.NextVal;
END;
Note:
user is "system"
table is "table_account"
The error that I get when I try to compile this is
PLS-00357: Table,View Or Sequence reference 'SEQUENCE1_ACCOUNT.NEXTVAL' not allowed in this context
So, does that mean I cannot use a sequence in a trigger?
Thanks in advance!
in His love,
HSHello,
Hoping for some help with sequence triggers as well.
CREATE TRIGGER "SCALS"."TRIGGER_CALL_NUM"
BEFORE INSERT ON "CALLLOG" FOR EACH ROW
BEGIN
select num_callers.NextVal into : new.callernumber from dual;
END;
Problem is that the trigger status is invalid ??
The error I get is in German (German installation)
Zeilen-# = 0 Spalten-# = 0 Fehlertext = PLS-00801: internal error [ph2csql_strdef_to_diana:bind]
Zeilen-# = 2 Spalten-# = 57 Fehlertext = PL/SQL: ORA-06544: PL/SQL: internal error, arguments: [ph2csql_strdef_to_diana:bind], [], [], [], [], [], [], []
Zeilen-# = 2 Spalten-# = 1 Fehlertext = PL/SQL: SQL Statement ignored
But perhaps something looks familiar??? -
Use of sequence numbers while inserting into tables
Hi,
Consider i have a stored procedure where i insert records into 30 to 40 tables.
for example i have a table A and a sequence SEQ_A for that table.
Is there any difference in performance in the following two ways of
insertion,
1. select SEQ_A.NEXTVAL into variable_a FROM DUAL;
INSERT INTO A VALUES(variable_a);
2.INSERT INTO A VALUES (SEQ_A.NEXTVAL).
I have 30 to 40 insert statements like that in method 1.
if i replace it by method 2. will there be any improvement in performance?
Thanks & Regards
SundarThis could be interesting. I agree that triggers should be used for data integrity, though even better is to only allow write access to tables via stored procedures.
Anyway while you are waiting for the test case that shows triggers are faster, which could take some time, it is quick and easy to come up with a test case that shows the opposite.
SQL> create table t (id number, dummy varchar2(1));
Table created.
real: 40
SQL> insert into t select s.nextval, 'a' from all_objects;
29625 rows created.
real: 5038
SQL> rollback;
Rollback complete.
real: 40
SQL> create trigger tt before insert on t
2 for each row
3 begin
4 select s.nextval into :new.id from dual;
5 end;
6 /
Trigger created.
real: 291
SQL> insert into t select null, 'a' from all_objects;
29626 rows created.
real: 13350
SQL> rollback;
Rollback complete.
real: 1082
SQL>Note with triggers even the rollback took longer.
Martin -
Using the Insert statement in a Java program without hardcoding the data
hello.
this is james mcfadden. i have developed a program called Demo.java, which is used with another program called QueryTableModel.java (a program that allows data to be viewed in a JTable). The Demo.java program displays a menu, connects to a database, allows the user to add data into the database and allows the user to view data that is already in the database. I have a problem with the Demo.java program. I have hardcoded the Insert statement in it. How do you use the Insert statement to put data into a database without hardcoding the data?
import java.awt.*;//Contains all of the classes for creating user interfaces and for painting graphics and images
import java.awt.event.*;//Provides interfaces and classes for dealing with different types of events fired by AWT components
import javax.swing.*;//Provides a set of lightweight components that, to the maximum degree possible, work the same on all platforms
import javax.swing.table.*;//Provides classes and interfaces for dealing with javax.swing.JTable
import javax.swing.JOptionPane;//provides a class that makes it easy to pop up a standard dialog box that prompts users for a value or informs them of something
import java.sql.*;//Provides the API for accessing and processing data stored in a data source using the Java programming language
public class Demo extends JFrame{
static String url = "jdbc:odbc:VideoLibrary";//a static variable that allows a connection to be made to a database called VideoLibrary
static Statement stmt;//a static variable that allows a statement to be made once a connection is set up
static Connection con;//a static interface that allows a connection to be made to a database
//global variables
JTextField hostField;//a class that allows a line of text to be changed
JTextField queryField;//a class that allows a line of text to be changed
QueryTableModel qtm;//a class that shows and changes regular two-dimensional tables of cells
JComboBox comboBox;//a class that puts a button or editable field and a drop-down list together
public static void main(String args[]){
int choice=-1;//a variable of type int that is set to -1
do{
choice=getChoice();//invokes the method getChoice()
if(choice!=0){
getSelected(choice);//invokes the method getSelected(choice)
}//end if
//if the user chooses 5, it will cause him or her to exit the system
}while(choice!=5);//end do-while
System.exit(0);//closes down the menu screen
}//end main
public static int getChoice(){
String choice;//a variable of type string
int ch;//a variable of type int
choice = JOptionPane.showInputDialog(null,"1. Maintain product details\n"+"2. Maintain member details\n"+"3. Maintain rental details\n"+"4. View product, member and rental details\n"+"5. Log Off\n\n"+"Enter your choice");//asks the user for some input
ch = Integer.parseInt(choice);//a class that wraps a value of the primitive type int in an object
return ch;//a method that returns an integer value
}//end getChoice
public static void getSelected(int choice){
if(choice==1){
maintainProductDetails();//invokes the method maintainProductDetails()
}//end if
if(choice==2){
maintainMemberDetails();//invokes the method maintainMemberDetails()
}//end if
if(choice==3){
maintainRentalDetails();//invokes the method maintainRentalDetails()
}//end if
if(choice==4){
Demo test = new Demo();//invokes the constructor Demo()
test.setVisible(true);//shows the JTable component by marking it as visible
}//end if
}//end getSelected
public static Connection getConnection(){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//used to create a JDBC connection using a database
}//end try
catch(java.lang.ClassNotFoundException e){//causes an exception to be thrown when an application tries to load in a class through its string name
System.err.print("ClassNotFoundException: ");//displays an error message
System.err.println(e.getMessage());//returns the exception that was raised if an error occurred while attempting to load the ClassNotFoundException class
}//end catch
try {
con=DriverManager.getConnection(url,"","");//tries to create a connection with the database using the DriverManager class
}//end try
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());//returns an SQL error message
}//end catch
return con;
}//end getConnection
public static void maintainProductDetails(){
Connection con = getConnection();//creates a connection with the database
String addProduct1, addProduct2, addProduct3, addProduct4, addProduct5, addProduct6, addProduct7, addProduct8, addProduct9, addProduct10;//string variables that represent information about the different types of product data that will be stored in the database
addProduct1 = "insert into Product values (110001, 'The Killers - Sams Town', 5.00, 'G', 'CD', 2006)";
addProduct2 = "insert into Product values (110002, 'Robbie Williams - Rudebox', 5.00, 'G', 'CD', 2006)";
addProduct3 = "insert into Product values (110003, 'Razorlight - Razorlight', 5.00, 'G', 'CD', 2006)";
addProduct4 = "insert into Product values (110004, 'My Chemical Romance - The Black Parade', 5.00, 'G', 'CD', 2006)";
addProduct5 = "insert into Product values (110005, 'Snow Patrol - Eyes Open', 5.00, 'G', 'CD', 2006)";
addProduct6 = "insert into Product values (110006, 'Scissor Sisters - Ta-Dah!', 5.00, 'G', 'CD', 2006)";
addProduct7 = "insert into Product values (110007, 'Lovesounds - Justin Timberlake', 5.00, 'G', 'CD', 2006)";
addProduct8 = "insert into Product values (110008, 'Director - We thrive on big cities', 5.00, 'G', 'CD', 2006)";
addProduct9 = "insert into Product values (110009, 'Roxette - Roxette hits', 5.00, 'G', 'CD', 2006)";
addProduct10 = "insert into Product values (110010, 'Pussy Cat Dolls - PCD', 5.00, 'G', 'CD', 2006)";
try {
stmt = con.createStatement();//Creates a Statement object for sending SQL statements to the database
//statements are allowed to be made once a connection is set up
stmt.executeUpdate(addProduct1);
stmt.executeUpdate(addProduct2);
stmt.executeUpdate(addProduct3);
stmt.executeUpdate(addProduct4);
stmt.executeUpdate(addProduct5);
stmt.executeUpdate(addProduct6);
stmt.executeUpdate(addProduct7);
stmt.executeUpdate(addProduct8);
stmt.executeUpdate(addProduct9);
stmt.executeUpdate(addProduct10);
stmt.close();//closes the Statement object
con.close();//terminates the connection with the database
}//end try
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());//returns an SQL error message
}//end catch
}//end maintainProductDetails
public static void maintainMemberDetails(){
Connection con = getConnection();//creates a connection with the database
String addMember1, addMember2, addMember3, addMember4, addMember5, addMember6, addMember7, addMember8, addMember9, addMember10;//string variables that represent information about the member data that will be stored in the database
addMember1 = "insert into Member values (1234, 'Ann', 'Smyth', 'Upper Killult, Falcarragh, Co. Donegal', '(074)-9135210', '(087)-2030172', #5/11/85#, #5/12/06#)";
addMember2 = "insert into Member values (2345, 'John', 'Murphy', 'Lower Killult, Falcarragh, Co. Donegal', '(074)-9135211', '(087)-2030173', #4/12/85#, #6/13/06#)";
addMember3 = "insert into Member values (1324, 'James', 'McFadden', 'Lower Ardsbeg, Gortahork, Co. Donegal', '(074)-9165314', '(087)-2030171', #4/11/85#, #6/14/06#)";
addMember4 = "insert into Member values (1235, 'Frankie', 'Ferry', 'Ardsmore, Gortahork, Co. Donegal', '(074)-9165325', '(087)-2031234', #6/13/60#, #6/15/06#)";
addMember5 = "insert into Member values (1236, 'Daniel', 'McKimm', 'Ballyness, Falcarragh, Co. Donegal', '(074)-9135212', '(087)-2030184', #5/14/73#, #6/16/06#)";
addMember6 = "insert into Member values (2346, 'Stephen', 'Doohan', 'Ballyness, Falcarragh, Co. Donegal', '(074)-9135213', '(087)-2030185', #6/13/85#, #5/13/06#)";
addMember7 = "insert into Member values (2347, 'James', 'Ferry', 'Meenlaragh, Gortahork, Co.Donegal', '(074)-9165360', '(087)-2031345', #9/12/85#, #5/14/06#)";
addMember8 = "insert into Member values (2348, 'Liam', 'Cannon', 'Derryconner, Gortahork, Co.Donegal', '(074)-9165324', '(087)-2031456', #4/11/86#, #5/15/06#)";
addMember9 = "insert into Member values (2401, 'Ciaran', 'Ferry', 'Brinalack, Gweedore, Co.Donegal', '(074)-9176425', '(087)-2030282', #9/12/85#, #5/16/06#)";
addMember10 = "insert into Member values (2402, 'Ciaran', 'McGee', 'Derrybeg, Gweedore, Co.Donegal', '(074)-9176536', '(087)-2030393', #9/14/85#, #5/18/06#)";
try{
stmt = con.createStatement();//Creates a Statement object for sending SQL statements to the database
//statements are allowed to be made once a connection is set up
stmt.executeUpdate(addMember1);
stmt.executeUpdate(addMember2);
stmt.executeUpdate(addMember3);
stmt.executeUpdate(addMember4);
stmt.executeUpdate(addMember5);
stmt.executeUpdate(addMember6);
stmt.executeUpdate(addMember7);
stmt.executeUpdate(addMember8);
stmt.executeUpdate(addMember9);
stmt.executeUpdate(addMember10);
stmt.close();//closes the Statement object
con.close();//terminates the connection with the database
}//end try
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());//returns an SQL error message
}//end catch
}//end maintainMemberDetails
public static void maintainRentalDetails(){
Connection con = getConnection();//creates a connection with the database
String addRental1, addRental2, addRental3, addRental4, addRental5, addRental6, addRental7, addRental8, addRental9, addRental10;//string variables that represent information about the loan data that will be stored in the database
addRental1 = "insert into Rental values (110001, 'The Killers - Sams Town', 1234, 'Ann', 'Smyth', #9/01/06#, #9/10/06#, 'Yes', 2.00)";
addRental2 = "insert into Rental values (120001, 'Mission Impossible 3', 2345, 'John', 'Murphy', #9/02/06#, #9/09/06#, 'No', 0.00)";
addRental3 = "insert into Rental values (130001, 'Need for Special Carbon', 1324, 'James', 'McFadden', #9/03/06#, #9/12/06#, 'Yes', 2.00)";
addRental4 = "insert into Rental values (110002, 'Robbie Williams - Rudebox', 1235, 'Frankie', 'Ferry', #9/04/06#, #9/11/06#, 'No', 0.00)";
addRental5 = "insert into Rental values (120015, 'Prime', 1236, 'Daniel', 'McKimm', #9/05/06#, #9/14/06#, 'Yes', 2.00)";
addRental6 = "insert into Rental values (130015, 'FIFA 07', 2346, 'Stephen', 'Doohan', #9/06/06#, #9/13/06#, 'No', 0.00)";
addRental7 = "insert into Rental values (110009, 'Roxette - Roxette hits', 2347, 'James', 'Ferry', #9/07/06#, #9/16/06#, 'Yes', 2.00)";
addRental8 = "insert into Rental values (120003, 'The Break Up', 2348, 'Liam', 'Cannon', #9/08/06#, #9/15/06#, 'No', 0.00)";
addRental9 = "insert into Rental values (130027, 'Gears of War', 2401, 'Ciaran', 'Ferry', #9/09/06#, #9/18/06#, 'Yes', 2.00)";
addRental10 = "insert into Rental values (110021, 'Scooter - Mind the Gap', 2402, 'Ciaran', 'McGee', #9/10/06#, #9/17/06#, 'No', 0.00)";
try{
stmt = con.createStatement();//Creates a Statement object for sending SQL statements to the database
//statements are allowed to be made once a connection is set up
stmt.executeUpdate(addRental1);
stmt.executeUpdate(addRental2);
stmt.executeUpdate(addRental3);
stmt.executeUpdate(addRental4);
stmt.executeUpdate(addRental5);
stmt.executeUpdate(addRental6);
stmt.executeUpdate(addRental7);
stmt.executeUpdate(addRental8);
stmt.executeUpdate(addRental9);
stmt.executeUpdate(addRental10);
stmt.close();//closes the Statement object
con.close();//terminates the connection with the database
}//end try
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());//returns an SQL error message
}//end catch
}//end maintainRentalDetails
public Demo(){//a constructor
super("Demo Test Frame");//overrides the constructor
setSize(350, 200);//Resizes this component so that it has width of 350 and height of 200
comboBox = new JComboBox();//invokes the class JComboBox
comboBox.addItem("jdbc:odbc:VideoLibrary");//adds the specified item to the end of the scrolling list
qtm = new QueryTableModel();//invokes the class QueryTableModel
JTable table = new JTable(qtm);//a class that shows and changes regular two-dimensional tables of cells
JScrollPane scrollpane = new JScrollPane(table);//a class that provides a scrollable view of a lightweight component
JPanel p1 = new JPanel();//a class that puts the combo box and query field in a panel
p1.setLayout(new GridLayout(3, 2));//Sets the layout manager for this container
p1.add(comboBox);//Appends the specified component to the end of this container
p1.add(new JLabel("Enter your query: "));//Appends the specified component to the end of this container
p1.add(queryField = new JTextField());//Appends the specified component to the end of this container
p1.add(new JLabel("Click here to send: "));//Appends the specified component to the end of this container
JButton jb = new JButton("Search");//a class that is an implementation of a "push" button
jb.addActionListener(new ActionListener(){//Adds an ActionListener to the button
public void actionPerformed(ActionEvent e){
qtm.setHostURL();//invokes the method setHostURL
qtm.setQuery(queryField.getText().trim());//invokes the method setQuery; and returns the text that is presented by this text component and returns a copy of the string, with leading and trailing whitespaces omitted
} );//end addActionListener
p1.add(jb);//Appends the specified component to the end of this container
getContentPane().add(p1, BorderLayout.NORTH);//Returns the content pane
getContentPane().add(scrollpane, BorderLayout.CENTER);//Returns the content pane
}//end Demo
}//end class Demo
import java.sql.*;//Provides the API for accessing and processing data stored in a data source using the Java programming language
import java.io.*;//Provides for system input and output through data streams, serialization and the file system
import java.util.Vector;//provides a class that implements a growable array of objects
import javax.swing.*;//Provides a set of lightweight components that, to the maximum degree possible, work the same on all platforms
import javax.swing.table.*;//Provides classes and interfaces for dealing with javax.swing.JTable
public class QueryTableModel extends AbstractTableModel{
Vector cache;//a class that constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero
int colCount;//a variable that counts the number of columns in the three tables
String[] headers;//a class that represents character strings and all string literals in this program are implemented as instances of the String class
Connection db;//an interface that allows a connection to be made to a database
Statement statement;//an interface that allows executes the given SQL statement, which returns a single ResultSet object
String currentURL;//a variable that allows the URL to be displayed in a combo box
public QueryTableModel(){//a constructor
cache=new Vector();//constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//used by opening a JDBC connection using an URL
}//end try
catch(Exception e){
System.out.println("problem loading the driver ");//an error message
}//end catch
}//end QueryTableModel
public String getColumnName(int i){//Returns the designated column's name
return headers;//returns the name of each column in the three table
}//end getColumnName
public int getColumnCount(){//Returns the number of columns in the column model
return colCount;//returns the number of columns in the three tables
}//end getColumnCount
public int getRowCount(){//Returns the number of rows in this table's model
return cache.size();//returns the number of components in the vector
}//end getRowCount
public Object getValueAt(int row, int col){//Returns the cell value at row and column
return ((String[])cache.elementAt(row))[col];//Returns the component at the specified index
}//end getValueAt
public void setHostURL(){//sets the URL for the database
String url = "jdbc:odbc:VideoLibrary";//a variable that allows a connection to be made to a database called VideoLibrary
closeDB();//invokes the method closeDB()
try{
db=DriverManager.getConnection(url,"","");//tries to create a connection with the database using the DriverManager class
statement=db.createStatement();//Creates a Statement object for sending SQL statements to the database
}//end try
catch(Exception e){
System.out.println("Could not initialize the database.");//an error message
e.printStackTrace();//a Throwable method that prints this throwable and it's backtrace to the standard error stream
}//end catch
}//end setHostURL
public void setQuery(String q){//sets the kind of query that is to be sent to the database
cache=new Vector();//constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero
String s="select * from Product";//a variable that causes all the data that is in the product table to be displayed in a JTable, which also means that all the data that is in both the member and rental tables can also be displayed in a JTable
try{
ResultSet rs=statement.executeQuery(q);//an interface that is used to generate a database result set by executing a statement that queries the database
ResultSetMetaData meta=rs.getMetaData();//an interface that is used to get information about the types and properties of the columns in a ResultSet object
colCount=meta.getColumnCount();//Returns the number of columns in this ResultSet object
headers=new String[colCount];//gets the name of each column in the three tables
for(int h=1;h<=colCount;h++){
headers[h-1]=meta.getColumnName(h);//Get the designated column's name
}//end for
while(rs.next()){
String[] record=new String[colCount];//stores the name of each column in the three tables in memory
for(int i=0;i<colCount;i++){
record[i]=rs.getString(i+1);//Retrieves the value of the designated column in the current row of this ResultSet object as a String
}//end for
cache.addElement(record);//Adds the specified component to the end of this vector, increasing its size by one
}//end while
fireTableChanged(null);//Forwards the given notification event to all TableModelListeners that registered themselves as listeners for this table model
}//end try
catch(Exception e){
cache=new Vector();//constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero
e.printStackTrace();//a Throwable method that prints this throwable and it's backtrace to the standard error stream
}//end catch
}//end setQuery
public void initDB(String url){
try{
db=DriverManager.getConnection(url);//tries to create a connection with the database using the DriverManager class
statement=db.createStatement();//Creates a Statement object for sending SQL statements to the database
}//end try
catch(Exception e){
System.out.println("Could not initialize the database.");//an error message
e.printStackTrace();//a Throwable method that prints this throwable and it's backtrace to the standard error stream
}//end catch
}//end initDB
public void closeDB(){
try{
if(statement!=null){
statement.close();//Releases this Statement object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed
}//end if
if(db!=null){
db.close();//Releases this Connection object's database and JDBC resources immediately instead of waiting for them to be automatically released
}//end if
}//end try
catch(Exception e){
System.out.println("Could not close the current connection.");//an error message
e.printStackTrace();//a Throwable method that prints this throwable and it's backtrace to the standard error stream
}//end catch
}//end closeDB
}//end class QueryTableModelhere's an uncommented version of the code.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.JOptionPane;
import java.sql.*;
public class Demo extends JFrame{
static String url = "jdbc:odbc:VideoLibrary";
static Statement stmt;
static Connection con;
JTextField hostField;
JTextField queryField;
QueryTableModel qtm;
JComboBox comboBox;
public static void main(String args[]){
int choice=-1;
do{
choice=getChoice();
if(choice!=0){
getSelected(choice);
}while(choice!=5);
System.exit(0);
public static int getChoice(){
String choice;
int ch;
choice = JOptionPane.showInputDialog(null,"1. Maintain product details\n"+"2. Maintain member details\n"+"3. Maintain rental details\n"+"4. View product, member and rental details\n"+"5. Log Off\n\n"+"Enter your choice");
ch = Integer.parseInt(choice);
return ch;
public static void getSelected(int choice){
if(choice==1){
maintainProductDetails();
if(choice==2){
maintainMemberDetails();
if(choice==3){
maintainRentalDetails();
if(choice==4){
Demo test = new Demo();
test.setVisible(true);
public static Connection getConnection(){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(java.lang.ClassNotFoundException e){
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
try {
con=DriverManager.getConnection(url,"","");
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
return con;
public static void maintainProductDetails(){
Connection con = getConnection();
String addProduct1, addProduct2, addProduct3, addProduct4, addProduct5, addProduct6, addProduct7, addProduct8, addProduct9, addProduct10;
addProduct1 = "insert into Product values (110001, 'The Killers - Sams Town', 5.00, 'G', 'CD', 2006)";
addProduct2 = "insert into Product values (110002, 'Robbie Williams - Rudebox', 5.00, 'G', 'CD', 2006)";
addProduct3 = "insert into Product values (110003, 'Razorlight - Razorlight', 5.00, 'G', 'CD', 2006)";
addProduct4 = "insert into Product values (110004, 'My Chemical Romance - The Black Parade', 5.00, 'G', 'CD', 2006)";
addProduct5 = "insert into Product values (110005, 'Snow Patrol - Eyes Open', 5.00, 'G', 'CD', 2006)";
addProduct6 = "insert into Product values (110006, 'Scissor Sisters - Ta-Dah!', 5.00, 'G', 'CD', 2006)";
addProduct7 = "insert into Product values (110007, 'Lovesounds - Justin Timberlake', 5.00, 'G', 'CD', 2006)";
addProduct8 = "insert into Product values (110008, 'Director - We thrive on big cities', 5.00, 'G', 'CD', 2006)";
addProduct9 = "insert into Product values (110009, 'Roxette - Roxette hits', 5.00, 'G', 'CD', 2006)";
addProduct10 = "insert into Product values (110010, '***** Cat Dolls - PCD', 5.00, 'G', 'CD', 2006)";
try {
stmt = con.createStatement();
stmt.executeUpdate(addProduct1);
stmt.executeUpdate(addProduct2);
stmt.executeUpdate(addProduct3);
stmt.executeUpdate(addProduct4);
stmt.executeUpdate(addProduct5);
stmt.executeUpdate(addProduct6);
stmt.executeUpdate(addProduct7);
stmt.executeUpdate(addProduct8);
stmt.executeUpdate(addProduct9);
stmt.executeUpdate(addProduct10);
stmt.close();
con.close();
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
public static void maintainMemberDetails(){
Connection con = getConnection();
String addMember1, addMember2, addMember3, addMember4, addMember5, addMember6, addMember7, addMember8, addMember9, addMember10;
addMember1 = "insert into Member values (1234, 'Ann', 'Smyth', 'Upper Killult, Falcarragh, Co. Donegal', '(074)-9135210', '(087)-2030172', #5/11/85#, #5/12/06#)";
addMember2 = "insert into Member values (2345, 'John', 'Murphy', 'Lower Killult, Falcarragh, Co. Donegal', '(074)-9135211', '(087)-2030173', #4/12/85#, #6/13/06#)";
addMember3 = "insert into Member values (1324, 'James', 'McFadden', 'Lower Ardsbeg, Gortahork, Co. Donegal', '(074)-9165314', '(087)-2030171', #4/11/85#, #6/14/06#)";
addMember4 = "insert into Member values (1235, 'Frankie', 'Ferry', 'Ardsmore, Gortahork, Co. Donegal', '(074)-9165325', '(087)-2031234', #6/13/60#, #6/15/06#)";
addMember5 = "insert into Member values (1236, 'Daniel', 'McKimm', 'Ballyness, Falcarragh, Co. Donegal', '(074)-9135212', '(087)-2030184', #5/14/73#, #6/16/06#)";
addMember6 = "insert into Member values (2346, 'Stephen', 'Doohan', 'Ballyness, Falcarragh, Co. Donegal', '(074)-9135213', '(087)-2030185', #6/13/85#, #5/13/06#)";
addMember7 = "insert into Member values (2347, 'James', 'Ferry', 'Meenlaragh, Gortahork, Co.Donegal', '(074)-9165360', '(087)-2031345', #9/12/85#, #5/14/06#)";
addMember8 = "insert into Member values (2348, 'Liam', 'Cannon', 'Derryconner, Gortahork, Co.Donegal', '(074)-9165324', '(087)-2031456', #4/11/86#, #5/15/06#)";
addMember9 = "insert into Member values (2401, 'Ciaran', 'Ferry', 'Brinalack, Gweedore, Co.Donegal', '(074)-9176425', '(087)-2030282', #9/12/85#, #5/16/06#)";
addMember10 = "insert into Member values (2402, 'Ciaran', 'McGee', 'Derrybeg, Gweedore, Co.Donegal', '(074)-9176536', '(087)-2030393', #9/14/85#, #5/18/06#)";
try{
stmt = con.createStatement();
stmt.executeUpdate(addMember1);
stmt.executeUpdate(addMember2);
stmt.executeUpdate(addMember3);
stmt.executeUpdate(addMember4);
stmt.executeUpdate(addMember5);
stmt.executeUpdate(addMember6);
stmt.executeUpdate(addMember7);
stmt.executeUpdate(addMember8);
stmt.executeUpdate(addMember9);
stmt.executeUpdate(addMember10);
stmt.close();
con.close();
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
public static void maintainRentalDetails(){
Connection con = getConnection();
String addRental1, addRental2, addRental3, addRental4, addRental5, addRental6, addRental7, addRental8, addRental9, addRental10;
addRental1 = "insert into Rental values (110001, 'The Killers - Sams Town', 1234, 'Ann', 'Smyth', #9/01/06#, #9/10/06#, 'Yes', 2.00)";
addRental2 = "insert into Rental values (120001, 'Mission Impossible 3', 2345, 'John', 'Murphy', #9/02/06#, #9/09/06#, 'No', 0.00)";
addRental3 = "insert into Rental values (130001, 'Need for Special Carbon', 1324, 'James', 'McFadden', #9/03/06#, #9/12/06#, 'Yes', 2.00)";
addRental4 = "insert into Rental values (110002, 'Robbie Williams - Rudebox', 1235, 'Frankie', 'Ferry', #9/04/06#, #9/11/06#, 'No', 0.00)";
addRental5 = "insert into Rental values (120015, 'Prime', 1236, 'Daniel', 'McKimm', #9/05/06#, #9/14/06#, 'Yes', 2.00)";
addRental6 = "insert into Rental values (130015, 'FIFA 07', 2346, 'Stephen', 'Doohan', #9/06/06#, #9/13/06#, 'No', 0.00)";
addRental7 = "insert into Rental values (110009, 'Roxette - Roxette hits', 2347, 'James', 'Ferry', #9/07/06#, #9/16/06#, 'Yes', 2.00)";
addRental8 = "insert into Rental values (120003, 'The Break Up', 2348, 'Liam', 'Cannon', #9/08/06#, #9/15/06#, 'No', 0.00)";
addRental9 = "insert into Rental values (130027, 'Gears of War', 2401, 'Ciaran', 'Ferry', #9/09/06#, #9/18/06#, 'Yes', 2.00)";
addRental10 = "insert into Rental values (110021, 'Scooter - Mind the Gap', 2402, 'Ciaran', 'McGee', #9/10/06#, #9/17/06#, 'No', 0.00)";
try{
stmt = con.createStatement();
stmt.executeUpdate(addRental1);
stmt.executeUpdate(addRental2);
stmt.executeUpdate(addRental3);
stmt.executeUpdate(addRental4);
stmt.executeUpdate(addRental5);
stmt.executeUpdate(addRental6);
stmt.executeUpdate(addRental7);
stmt.executeUpdate(addRental8);
stmt.executeUpdate(addRental9);
stmt.executeUpdate(addRental10);
stmt.close();
con.close();
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
public Demo(){
super("Demo Test Frame");
setSize(350, 200);
comboBox = new JComboBox();
comboBox.addItem("jdbc:odbc:VideoLibrary");
qtm = new QueryTableModel();
JTable table = new JTable(qtm);
JScrollPane scrollpane = new JScrollPane(table);
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(3, 2));
p1.add(comboBox);
p1.add(new JLabel("Enter your query: "));
p1.add(queryField = new JTextField());
p1.add(new JLabel("Click here to send: "));
JButton jb = new JButton("Search");
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
qtm.setHostURL();
qtm.setQuery(queryField.getText().trim());
p1.add(jb);
getContentPane().add(p1, BorderLayout.NORTH);
getContentPane().add(scrollpane, BorderLayout.CENTER);
import java.sql.*;
import java.io.*;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.*;
public class QueryTableModel extends AbstractTableModel{
Vector cache;
int colCount;
String[] headers;
Connection db;
Statement statement;
String currentURL;
public QueryTableModel(){
cache=new Vector();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(Exception e){
System.out.println("problem loading the driver ");
public String getColumnName(int i){
return headers;
public int getColumnCount(){
return colCount;
public int getRowCount(){
return cache.size();
public Object getValueAt(int row, int col){
return ((String[])cache.elementAt(row))[col];
public void setHostURL(){
String url = "jdbc:odbc:VideoLibrary";
closeDB();
try{
db=DriverManager.getConnection(url,"","");
statement=db.createStatement();
catch(Exception e){
System.out.println("Could not initialize the database.");
e.printStackTrace();
public void setQuery(String q){
cache=new Vector();
String s="select * from Product";
try{
ResultSet rs=statement.executeQuery(q);
ResultSetMetaData meta=rs.getMetaData();
colCount=meta.getColumnCount();
headers=new String[colCount];
for(int h=1;h<=colCount;h++){
headers[h-1]=meta.getColumnName(h);
while(rs.next()){
String[] record=new String[colCount];
for(int i=0;i<colCount;i++){
record[i]=rs.getString(i+1);
cache.addElement(record);
fireTableChanged(null);
catch(Exception e){
cache=new Vector();
e.printStackTrace();
public void initDB(String url){
try{
db=DriverManager.getConnection(url);
statement=db.createStatement();
catch(Exception e){
System.out.println("Could not initialize the database.");
e.printStackTrace();
public void closeDB(){
try{
if(statement!=null){
statement.close();
if(db!=null){
db.close();
catch(Exception e){
System.out.println("Could not close the current connection.");
e.printStackTrace();
Maybe you are looking for
-
VPN License question on 5505 ASA Firewall
Inherited a firewall project, it's getting a VPN running on a ASA 5505 Firewall for remote workers. Firewall was configured by someone else who isn't available. Basic question on the License: The current license is good for 2 SSL VPN Peers, and 20
-
"The disk cannot be read from or written to" or
I recently updated my itouch software to the 3.1.2 software and when i restored it like I was supposed to my songs synced onto my itouch but you couldn't see them. On my computer it said my music was on my itouch but when I went to my library on my i
-
My artists section on my ipod keeps crashing ever i click it and the whole app closes
So bassicaly when ever i click on my artists in my music app it will just crash and the while app will just close
-
Cost capture for Rework for Incoming Inspections
Hi xperts, Scenario Incoming inspection, QC department checks and finds rejects No UD stock posting is done. They use in house personnel for reworking the partial rejects they have. (This is because they have imported raw materials with lead time of
-
Cancel the query which uses full transaction log file
Hi, We have reindexing job to run every week sunday. During the last run, the transaction log got full and the subsequent transactions to the database got errorred out stating 'Transaction log is full'. I want to restrict the utilization of the log f