Use of "infotypes" statement
Hi,
What is the use of infotypes statement.
I saw a code block in sdn. here they have used a infotype statement as below.
infotypes: 0041.
tables: pernr.
data: record type standard table of p0041,
lfs_rec like line of record.
parameters: p_pernr type persno.
start-of-selection.
call function 'HRAR_READ_INFOTYPE'
exporting
personnel_number = p_pernr
infotype = '0041'
IMPORTING
RC = RC
tables
infotype_table = record
exceptions
exception_infotype = 1.
loop at record into lfs_rec.
write:/10 lfs_rec-pernr,
30 lfs_rec-begda,
42 lfs_rec-endda,
54 lfs_rec-dar01,
60 lfs_rec-dat01.
endloop.
In the above code they have used
infotypes: 0041.
But 0041 is not used anywhere in the program.
I have read that infotypes statement is used to create a internal table. But here i have no clue they have craeted internal table separately.
Please help
Thanks in advance,
Bala.
hi Bala,
You are right, infotypes statement is used to create a internal table. Infotype can be used as reference to the standard table. eg if we consider the case of standard table PA0001, then is infotype is 0001.
in case of this code:
call function 'HRAR_READ_INFOTYPE'
exporting
personnel_number = p_pernr
infotype = '0041'
IMPORTING
RC = RC
tables
infotype_table = record
exceptions
exception_infotype = 1.
we are passing infotype as '0041', so it will read from standard table PA0041 and it will fetch data from that table according to p_pernr and the data will be fetched into the internal table 'record'. That is why infotypes are used.
I hope this explaination is sufficient.
regards
arjun.
Similar Messages
-
Custom infotype- Infotypes statement
I am getting error when I declare custom infotype in "INFOTYPES" statement in my program, pl advise what attributes are misssing
hi Nagarjuna,
the statement INFOTYPES can be declared if your porgram use an LDB.
If you need a table entry from a custom infotype you should use a code like this:
data: lw_custom_infotype type P9XXX .
hope this is helpfull
regards . -
How can i use one SQL statement to solve problem?
How can i use one SQL statement to solve the question below?
For a Table named A, there is a column named F(char type).
Now select all the records where F like '%00' and update their F value to '%01'
Just one SQL statement.Do not use PL/SQL block.
How to do that?
Thanks.What is the data volume for this table?
Do you expect lots of rows to have '%00' as their value?
Following two statements come to mind. Other experts would be able to provide better alternatives:
If you have index on SUBSTR(f, 2):
UPDATE A
SET f = SUBSTR(f,
1,
length(f) - 2) || '01'
WHERE substr(f,
-2) = '00';If most of the rows have pattern '%00':
UPDATE A
SET f = SUBSTR(f,
1,
length(f) - 2) ||
DECODE(SUBSTR(f,
-2),
'00',
'01',
SUBSTR(f,
-2)); -
Use of Prepared Statement in adf
Hi Experts,
I am confused with the Use of prepared statement in adf.
My use case is ,
I have to update a table from every page in my application under certain conditions.
My question is ,
whether I have to create the VO iterator binding in every page and by calling the createinsert and insert the data in to the table or
use a common method in the Application module impl
which is using a prepared statement,(which is not even creating the ViewObject ) like
PreparedStatement st = null;
String sql = "INSERT INTO hr.departments (DEPARTMENT_ID, DEPARTMENT_NAME, MANAGER_ID, LOCATION_ID) VALUES (seq,?,?,?)";
st=getDBTransaction().createPreparedStatement(sql,0);
st.setString(1, name);
st.setString(2, mgr_id);
st.setString(3, Loc_id);
st.execute();
getDBTransaction().commit();which is the best approach?
Studio Edition Version 11.1.1.2.0
RanjithRanjith,
Without further understanding the use case, there's not really much difference between the two approaches. In both cases, you'd have a binding in the page definition (either an iterator binding for the VO or a method binding for the AM service method). Both will use bind variables. The main difference I can see is that, depending on how you have configured your AM pooling settings, the VO method will incur fewer parses in the DB because the AM will cache prepared statements for you.
John -
How can I use an IF statement in the SELECT
Hi People,
I have a procedure called ENQUEUE_PROC which takes 3 parameters.
and I am trying to use an if statement in the select. I appreciate the help with this task.
here is my code.
Please have a look at my Select statement. What I have does not compile, however it might give you an idea of what i need.
PROCEDURE ENQUEUE_PROC(P_SUBMISSION_ID NUMBER,
P_EVENT VARCHAR2,
CASE_TYPE_CODE NUMBER;
) AS
XMLDATA XMLTYPE;
enqueue_options dbms_aq.enqueue_options_t;
message_properties dbms_aq.message_properties_t;
message_handle RAW(16);
message SYS.AQ$_JMS_TEXT_MESSAGE;
BEGIN
SELECT
XMLELEMENT("caseFileEvent", XMLATTRIBUTES('http://www.ussc.gov/soa/casefile/event/types' AS "xmlns",
'http://www.ussc.gov/soa/casefile/event/types' AS "xmlns:ns0"),
XMLELEMENT("caseFileUploadEvent", XMLATTRIBUTES('http://www.w3.org/2001/XMLSchema-instance' AS "xmlns:xsi",
'http://www.ussc.gov/soa/casefile/event/types ../xsd/Case_META.xsd' AS "xsi:schemaLocation",
'http://www.ussc.gov/soa/casefile/event/types' AS "xmlns"),
XMLELEMENT("taskEvent", P_EVENT), --eg - 'SUBMIT', 'REJECT', 'RESUBMIT'
XMLELEMENT("defendentDetails",
XMLELEMENT("sentensingDate", SMD.SENT_VIO_DATE),
XMLELEMENT("personDetails",
// Here is where I want my IF statement, *********************************
IF CASE_TYPE_CODE = 10 THEN
XMLELEMENT("personNameDetails",
XMLELEMENT("firstName", SMD.FIRST_NAME),
XMLELEMENT("middleName", SMD.MIDDLE_NAME),
XMLELEMENT("lastName", SMD.LAST_NAME)
), -- personNameDetails
ELSE
XMLELEMENT("personNameDetails",
XMLELEMENT("corpname", SMD.CORPNAME),
), -- personNameDetails
XMLELEMENT("dateOfBirth", SMD.BIRTH_DATE)
) -- personDetails
), -- defendentDetails
XMLELEMENT("documentStatusDetails",
XMLELEMENT("otherStatus",
XMLELEMENT("intCode", NULL),
XMLELEMENT("description", NULL)
) -- otherStatus
), -- documentStatusDetails
XMLELEMENT("uploadOtherDetails",
XMLELEMENT("submissionId", SUB.SUBMISSION_ID),
XMLELEMENT("submissionSessionId", SUB.SUB_SESSION_ID),
XMLELEMENT("submissionMethod",
XMLELEMENT("intCode", SUB.SUB_MTHD_CODE),
XMLELEMENT("description", SM.DESCRIP)
), -- submissionMethod
XMLELEMENT("submissionReason",
XMLELEMENT("intCode", SUB.SUB_TYPE_CODE),
XMLELEMENT("description", SR.DESCRIP)
), -- submissionReason
XMLELEMENT("district",
XMLELEMENT("intCode", SMD.DIST_ID),
XMLELEMENT("description", D.DISTRICT_NAME)
), -- district
XMLELEMENT("caseFileType",
XMLELEMENT("intCode", SUB.CASE_TYPE_CODE),
XMLELEMENT("description", C.DESCRIP)
), -- caseFileType
XMLELEMENT("primaryDocketInfo",
XMLELEMENT("yearYY", SUBSTR(SMD.DOCKET, 1, 2)),
XMLELEMENT("id", SUBSTR(SMD.DOCKET, 3, 7)),
XMLELEMENT("defendentNumber", SMD.DEF_NUM)
), -- primaryDocketInfo
XMLELEMENT("PACTSId", SMD.PACTS_ID), -- PACTSId
XMLELEMENT("AOJudgeId",
XMLELEMENT("intCode", SMD.AO_JUDGE_ID),
XMLELEMENT("description", J.LAST_NAME || ', ' || J.FIRST_NAME || ', ' || J.MIDDLE_NAME)
), -- AOJudgeId
XMLELEMENT("missingCasefile", SUB.MISSING_CASE), -- missingCasefile
XMLELEMENT("creator",
XMLELEMENT("firstName", NULL),
XMLELEMENT("lastName", NULL),
XMLELEMENT("email", SUB.CREATOR_ID),
XMLELEMENT("actionDate", REGEXP_REPLACE( TO_CHAR(SUB.CREATE_TIME, 'YYYY-MM-DD"T"HH24:MI:SS.FFTZR'), '...(......)$', '\1'))
), -- creator
XMLELEMENT("lastModifier",
XMLELEMENT("firstName", NULL),
XMLELEMENT("lastName", NULL),
XMLELEMENT("email", H.USER_ID),
XMLELEMENT("actionDate", TO_CHAR(H.ACTION_DATE, 'YYYY-MM-DD"T"HH24:MI:SS".000-05:00"'))
) -- lastModifier
) -- uploadOtherDetails
) -- caseFileUploadEvent
) -- caseFileEvent
INTO XMLDATA
FROM USSC_CASES.SUBMISSION SUB,
USSC_CASES.SUBMISSION_METADATA SMD,
USSC_CASES.CASE_HISTORY H,
LOOKUP.CASE_SUB_MTHD SM,
LOOKUP.CASE_SUB_TYPE SR,
LOOKUP.DISTRICTS D,
LOOKUP.JUDGES J,
LOOKUP.CASE_TYPES C
WHERE SUB.SUBMISSION_ID = SMD.SUBMISSION_ID
AND SUB.SUBMISSION_ID = H.SUBMISSION_ID
AND SUB.SUB_MTHD_CODE = SM.SUBMTHD_CODE
AND SUB.SUB_TYPE_CODE = SR.SUBTYPE_CODE
AND SUB.CASE_TYPE_CODE = C.CASE_TYPE_CODE
AND SMD.DIST_ID = D.USSC_DISTRICT_ID
AND SMD.AO_JUDGE_ID = J.AO_JUDGE_ID
AND H.ACTION_DATE IN (SELECT MAX(A.ACTION_DATE)
FROM USSC_CASES.CASE_HISTORY A
WHERE A.SUBMISSION_ID = P_SUBMISSION_ID)
AND SUB.SUBMISSION_ID = P_SUBMISSION_ID;
--dbms_output.put_line('queue start '|| xmldata.getclobval());
--insert into test1 values(xmldata);
message := SYS.AQ$_JMS_TEXT_MESSAGE.construct;
message.set_text(xmldata.getStringVal());
DBMS_AQ.ENQUEUE(queue_name => 'case_file_queue', -- aqadm.cases_queue
enqueue_options => enqueue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
COMMIT;
END ENQUEUE_PROC;thanks for the help,
I believe I almost got it to compilw, however I am getting Error(29,19): PL/SQL: ORA-00918: column ambiguously defined.
Of course CASE_TYPE_CODE is ambiguously because its passed in, is there a way around this.
Here is what i have so far.
PROCEDURE ENQUEUE_PROC(P_SUBMISSION_ID NUMBER,
P_EVENT VARCHAR2,
CASE_TYPE_CODE NUMBER // passed in field
) AS
XMLDATA XMLTYPE;
enqueue_options dbms_aq.enqueue_options_t;
message_properties dbms_aq.message_properties_t;
message_handle RAW(16);
message SYS.AQ$_JMS_TEXT_MESSAGE;
BEGIN
SELECT
XMLELEMENT("caseFileEvent", XMLATTRIBUTES('http://www.ussc.gov/soa/casefile/event/types' AS "xmlns",
'http://www.ussc.gov/soa/casefile/event/types' AS "xmlns:ns0"),
XMLELEMENT("caseFileUploadEvent", XMLATTRIBUTES('http://www.w3.org/2001/XMLSchema-instance' AS "xmlns:xsi",
'http://www.ussc.gov/soa/casefile/event/types ../xsd/Case_META.xsd' AS "xsi:schemaLocation",
'http://www.ussc.gov/soa/casefile/event/types' AS "xmlns"),
XMLELEMENT("taskEvent", P_EVENT), --eg - 'SUBMIT', 'REJECT', 'RESUBMIT'
XMLELEMENT("defendentDetails",
XMLELEMENT("sentensingDate", SMD.SENT_VIO_DATE),
CASE
WHEN CASE_TYPE_CODE = 10 THEN
XMLELEMENT("personDetails",
XMLELEMENT("personNameDetails",
XMLELEMENT("firstName", SMD.FIRST_NAME),
XMLELEMENT("middleName", SMD.MIDDLE_NAME),
XMLELEMENT("lastName", SMD.LAST_NAME)
), -- personNameDetails
XMLELEMENT("dateOfBirth", SMD.BIRTH_DATE)
) -- personDetails
ELSE
XMLELEMENT("corporationDetails",
XMLELEMENT("organizationName", SMD.CORP_NAME)
) -- corporationDetails
END
), -- defendentDetails
XMLELEMENT("documentStatusDetails",
XMLELEMENT("otherStatus",
XMLELEMENT("intCode", NULL),
XMLELEMENT("description", NULL)
) -- otherStatus
), -- documentStatusDetails
XMLELEMENT("uploadOtherDetails",
XMLELEMENT("submissionId", SUB.SUBMISSION_ID),
XMLELEMENT("submissionSessionId", SUB.SUB_SESSION_ID),
XMLELEMENT("submissionMethod",
XMLELEMENT("intCode", SUB.SUB_MTHD_CODE),
XMLELEMENT("description", SM.DESCRIP)
), -- submissionMethod
XMLELEMENT("submissionReason",
XMLELEMENT("intCode", SUB.SUB_TYPE_CODE),
XMLELEMENT("description", SR.DESCRIP)
), -- submissionReason
XMLELEMENT("district",
XMLELEMENT("intCode", SMD.DIST_ID),
XMLELEMENT("description", D.DISTRICT_NAME)
), -- district
XMLELEMENT("caseFileType",
XMLELEMENT("intCode", SUB.CASE_TYPE_CODE),
XMLELEMENT("description", C.DESCRIP)
), -- caseFileType
XMLELEMENT("primaryDocketInfo",
XMLELEMENT("yearYY", SUBSTR(SMD.DOCKET, 1, 2)),
XMLELEMENT("id", SUBSTR(SMD.DOCKET, 3, 7)),
XMLELEMENT("defendentNumber", SMD.DEF_NUM)
), -- primaryDocketInfo
XMLELEMENT("PACTSId", SMD.PACTS_ID), -- PACTSId
XMLELEMENT("AOJudgeId",
XMLELEMENT("intCode", SMD.AO_JUDGE_ID),
XMLELEMENT("description", J.LAST_NAME || ', ' || J.FIRST_NAME || ', ' || J.MIDDLE_NAME)
), -- AOJudgeId
XMLELEMENT("missingCasefile", SUB.MISSING_CASE), -- missingCasefile
XMLELEMENT("creator",
XMLELEMENT("firstName", NULL),
XMLELEMENT("lastName", NULL),
XMLELEMENT("email", SUB.CREATOR_ID),
XMLELEMENT("actionDate", REGEXP_REPLACE( TO_CHAR(SUB.CREATE_TIME, 'YYYY-MM-DD"T"HH24:MI:SS.FFTZR'), '...(......)$', '\1'))
), -- creator
XMLELEMENT("lastModifier",
XMLELEMENT("firstName", NULL),
XMLELEMENT("lastName", NULL),
XMLELEMENT("email", H.USER_ID),
XMLELEMENT("actionDate", TO_CHAR(H.ACTION_DATE, 'YYYY-MM-DD"T"HH24:MI:SS".000-05:00"'))
) -- lastModifier
) -- uploadOtherDetails
) -- caseFileUploadEvent
) -- caseFileEvent
INTO XMLDATA
FROM USSC_CASES.SUBMISSION SUB,
USSC_CASES.SUBMISSION_METADATA SMD,
USSC_CASES.CASE_HISTORY H,
LOOKUP.CASE_SUB_MTHD SM,
LOOKUP.CASE_SUB_TYPE SR,
LOOKUP.DISTRICTS D,
LOOKUP.JUDGES J,
LOOKUP.CASE_TYPES C
WHERE SUB.SUBMISSION_ID = SMD.SUBMISSION_ID
AND SUB.SUBMISSION_ID = H.SUBMISSION_ID
AND SUB.SUB_MTHD_CODE = SM.SUBMTHD_CODE
AND SUB.SUB_TYPE_CODE = SR.SUBTYPE_CODE
AND SUB.CASE_TYPE_CODE = C.CASE_TYPE_CODE
AND SMD.DIST_ID = D.USSC_DISTRICT_ID
AND SMD.AO_JUDGE_ID = J.AO_JUDGE_ID
AND H.ACTION_DATE IN (SELECT MAX(A.ACTION_DATE)
FROM USSC_CASES.CASE_HISTORY A
WHERE A.SUBMISSION_ID = P_SUBMISSION_ID)
AND SUB.SUBMISSION_ID = P_SUBMISSION_ID;
--dbms_output.put_line('queue start '|| xmldata.getclobval());
--insert into test1 values(xmldata);
message := SYS.AQ$_JMS_TEXT_MESSAGE.construct;
message.set_text(xmldata.getStringVal());
DBMS_AQ.ENQUEUE(queue_name => 'case_file_queue', -- aqadm.cases_queue
enqueue_options => enqueue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
COMMIT;
END ENQUEUE_PROC;Edited by: Rooney on Jan 31, 2012 1:55 PM -
Using A callable statement in java
Hi all im trying to get results back from the database using a callable statement the problem is that it is placing / infront of single quotes.I need to get rid of this because it's not returning anything
here is my code
CallableStatement statementOne;
statementOne = ComparitiveAnalysisGUI.conn.prepareCall("{call graphProc(?,?,?,?,?,?,?)}");
statementOne.setString(1,"\"date_format(calldate, '%Y-%m-%d H:59:59'),avg(billsec)\"");
statementOne.setString(2,"Clovercdr");
statementOne.setString(3,start);
statementOne.setString(4,end);
statementOne.setString(5,"Boksburg");
statementOne.setString(6,"\"billsec > 0 and Network = " + network + "\"");
statementOne.setString(7,"\"date_format(calldate, '%Y-%m-%d %H:M:S')\"");
System.out.println(statementOne.toString());
rs = statementOne.executeQuery();
the result of the println is
com.mysql.jdbc.CallableStatement@ec4a87: CALL graphProc('"date_format(calldate, \'%Y-%m-%d %H:59:59\'),avg(billsec)"','Clovercdr','\'2006-03-14 00:00:01\'','\'2006-03-14 23:59:59\'','Boksburg','"billsec > 0 and Network = \'SAMobile\'"','"date_format(calldate, \'%Y-%m-%d %H:M:S\')"')
as you can see quite a mess please help if you can get the statement to look as follows
CALL graphProc("date_format(calldate, '%Y-%m-%d %H:59:59'),avg(billsec)",'Clovercdr','2006-03-14 00:00:01','2006-03-14 23:59:59','Boksburg',"billsec > 0 and Network = 'SAMobile'","date_format(calldate, '%Y-%m-%d %H:M:S')")
thanks BrianOk in order to understand why I did what I did parhaps it would be best if you saw my Stored procedure
create procedure graphProc(col varchar(100),company varchar(20),startTime datetime,endTime datetime,branchName varchar(20),andSection varchar(200),groupSec varchar(100))
BEGIN
SET @stmt := CONCAT("SELECT ",col," from ",company," where calldate between '",startTime,"' and '",endTime,"' and branchName = '",branchName,"' and ",andSection," Group by ",groupSec);
PREPARE stmt1 from @stmt;
EXECUTE stmt1;
the call is for example
call graphProc("date_format(calldate, '%Y-%m-%d %H:59:59'),avg(billsec)",'Clovercdr','2006-03-01 00:00:01','2006-03-14 23:59:59','Boksburg',"billsec > 0 and date_format(calldate, '%k') BETWEEN 7 AND 19 and Network = 'SAMobile'","date_format(calldate, '%Y-%m-%d %H:M:S')")//
as you can see In MySQL the "date_format(calldate, '%Y-%m-%d %H:59:59'),avg(billsec)" has to be quoted like this, so it can recognise it as a single parameter, since , '%Y-%m-%d %H:59:59' is viewed as another parameter
thaks for your reply
Brian -
How to use an if statement in javascript code
Hello,
I have a batch processing script to search for text "employee signature" on each page in a multiple page file and to then list in the console any pages that do not have the "Employee Signature" text included.
The script is not yet functional as an if statement needs to be included.
Can anyone please advise how to use an if statement in javascript code?
var numpages = this.numPages;
for (var i=0; i < numpages; i++)
search.query("Employee Signature", "ActiveDoc");
console.println('Pages that do not include an employee signature: ' + this.pageNum +' ');
Any assistance will be most appreciated.Thank you very much for your assistance try.
I have modified the code as suggested and the page numbers are now listing correctly, thank you, but....................,
The console lists every page as having an "employee signature" when there are pages in the document that do not have an employee signature.
The code (revised as follows) is not processing the "getPageNthWord part of the statement" in the console report?
Can you please advise where the code needs reworking?
var ckWords; // word pair to test
var bFound = false; // logical status of found words
// loop through pages
for (var i = 0; i < this.numPages; i++ ) {
bFound = false; // set found flag to false
numWords = this.getPageNumWords(i); // number of words on page
// loop through the words on page
for (var j = 0; j < numWords; j++) {
// get word pair to test
ckWords = this.getPageNthWord(i, j) + ' ' + this.getPageNthWord(i, j + 1); // test words
// check to see if word pair is 'Employee' string is present
if ( ckWord == "Employee") {
bFound = true; // indicate found logical value
console.println('Pages that includes an employee signature: ' + (i + 1) +' ');
break; // no need to further test for this page
} // end Employee Signature
} // end word loop
// test to see if words not found
if(bFound == false) {
console.println('Pages that do include an employee signature: ' + (i + 1) +' ');
} // end not found on page
} // end page loop
Thank you -
What happen if i use controll break statement in between select & endselect
Hi all,
what happen if i use controll break statement in between select & endselect ?
Thanks in Advance
KRHi for reference u can go through this code example
data:
fs_tab like sflight.
data:
t_tab like standard table of fs_tab.
select * from sflight into table t_tab.
loop at t_tab into fs_tab.
write: / fs_tab-carrid.
endloop.
refresh t_tab.
clear fs_tab.
select * from sflight into fs_tab.
at new fs_tab-carrid.
append fs_tab to t_tab.
endat.
endselect. -
Need help in using a case statement in expression operator
Hi All,
I am using OWB version 10.2.0.1.0.
My requirement is to add a new column called call _zone_key in expression operator and map it to the target table. I need to use the below expression for populating call_zone_key values
Expression:
case when (INGRP1.CHARGETYPE in ('O','F') or INGRP1.TARIFF_GROUP in ('SMSINT','MMSINT')or ( INGRP1.CALL_TYPE = '002' and INGRP1.TARIFF_GROUP = 'MTV'))
then
(select call_zone_reltn_key from call_zone_reltn where
call_zone_cd=substr(case
when substr( INGRP1.B_SUBNO,1,2)='00'
then
substr( INGRP1.B_SUBNO,3)
else substr( INGRP1.B_SUBNO,1)
end,1,length(call_zone_cd))and rownum=1)
else -1
end
All the columns needed for using the above expression is available in INGRP1 but still I am unable to deploy the mapping using above expression. Call_zone_reltn table is also imported to the module. I am getting below error
Error:
Warning
ORA-06550: line 4980, column 2:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( - + case mod new not null others <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall merge time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set specification>
<an alternativ
NEW_MOD_MAP_CELL_USAGE_FCT_PRE
Create
Warning
ORA-06550: line 4989, column 43:
PLS-00103: Encountered the symbol ")" when expecting one of the following:
* & - + ; / at for mod remainder rem <an exponent (**)> and
or group having intersect minus order start union where
connect || multiset
If i replace the expression with numbers such as 1 or 2, I am able to deploy the mapping.
Kindly help in fixing this issue.
Thanks,
KabilanYou can't use the SELECT statement inside the expression, you need to join both tables before the expression. Use a Join operator with this JOIN condition:
CALCULATED_CALL_ZONE_CD = call_zone_reltn.call_zone_cd ( + )
Where Calculated_call_zone_cd proceed from a previous expression:
CALCULATED_CALL_ZONE_CD = substr(case when substr( INGRP1.B_SUBNO,1,2)='00' then substr( INGRP1.B_SUBNO,3) else substr( INGRP1.B_SUBNO,1) end,1,length(call_zone_cd))
And after joining both tables, you can use another expression to get the rownum, then another filter operator to keep only the rownum = 1, and now you can use your expression without the SELECT, using the call_zone_cd column from the outgroup in the joiner operator (you need to include that column in the filter operator to use it).
Regards
ANA GH -
How do I use the CASE statement in the where clause?
Hello Everyone,
I have 2 queries that do what I need to do but I am trying to learn how to use the CASE statement.
I have tried to combine these 2 into one query using a case statement but don't get the results I need.
Could use some help on how to use the case syntax to get the results needed.
thanks a lot
select segment_name,
product_type,
count (distinct account_id)
FROM NL_ACCT
where
ind = 'N'
and
EM_ind = 'N'
and product_type in ('TAX','PAY')
and acct_open_dt between (cast('2006-01-17' as date)) and (cast('2006-01-17' as date) + 60)
GROUP BY 1,2
order by product_type
select segment_name,
product_type,
count (distinct account_id)
FROM NL_ACCT
where
ind = 'N'
and
EM_ind = 'N'
and product_type not in ('TAX','PAY')
and acct_open_dt between (cast('2006-01-17' as date)) and (cast('2006-01-17' as date) + 30)
group by 1,2
order by product_typeSomething like:
SELECT segment_name, product_type,
SUM(CASE WHEN account_id IN ('TAX','PAY') and
acct_open_dt BETWEEN TO_DATE('2006-01-17', 'yyyy-mm-dd') and
TO_DATE('2006-01-17', 'yyyy-mm-dd') + 60 THEN 1
ELSE 0 END) tax_pay,
SUM(CASE WHEN account_id NOT IN ('TAX','PAY') and
acct_open_dt BETWEEN TO_DATE('2006-01-17', 'yyyy-mm-dd') and
TO_DATE('2006-01-17', 'yyyy-mm-dd') + 30 THEN 1
ELSE 0 END) not_tax_pay
FROM NL_ACCT
WHERE ind = 'N' and
em_ind = 'N' and
acct_open_dt BETWEEN TO_DATE('2006-01-17', 'yyyy-mm-dd') and
TO_DATE('2006-01-17', 'yyyy-mm-dd') + 60
GROUP BY segment_name, product_type
ORDER BY product_typeNote: You cannor GROUP BY 1,2, you need to explicitly name the columns to group by.
HTH
John -
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(); -
HELP -menu using a switch statement
Hello to all. I'm new to the Java world, but currently taking my first Java class online. Not sure if this is the right place, but I need some help. In short I need to write a program that gives the user a menu to chose from using a switch statement. The switch statement should include a while statement so the user can make more than one selection on the menu and provide an option to exit the program.
With in the program I am to give an output of all counting numbers (6 numbers per line).
Can anyone help me with this?? If I'm not asking the right question please let me know or point me in the direction that can help me out.
Thanks in advance.
Here is what I have so far:
import java.util.*;
public class DoWhileDemo
public static void main(String[] args)
int count, number;
System.out.println("Enter a number");
Scanner keyboard = new Scanner (System.in);
number = keyboard.nextInt();
count = number;
do
System.out.print(count +",");
count++;
}while (count <= 32);
System.out.println();
System.out.println("Buckle my shoe.");
}Thanks for the reply. I will tk a look at the link that was provided. However, I have started working on the problem, but can't get the 6 numbers per line. I am trying to figure out the problem in parts. Right now I'm working on the numbers, then the menu, and so on.
Should I tk this approach or another?
Again, thanks for the reply. -
How to use the Include Statement in the BADI
Dear All,
I am trying to implement the BADI. So i need to use the Include in the BADI.
How to use the Include statement in the BADI. I cant able to use it in the Public, Private and protected statement.
Where should i mention that,,,,
Thanks
YogeshHi Sharat,
Thanks for your reply.
I need to use the BADI HRWPC_PCR_APPR_FORM. In which the values are available in the Container. So if i need to use the container values then i need to use that include <cntain>.
Is there any possible ways to make it.
Thanks
Yogesh -
Update multiple rows & columns using a single statement
I have the following table with tablename - emp
first_name last_name age
aaa bbb 31
56
78
ggg hhh 36
2nd & 3rd row contain null values (no data) in first_name & last_name column . I want to update those two rows with data using a single statement. How do I do it?
I was thinking may be something like the following:-
UPDATE emp
SET first_name= , last_name=
CASE
WHEN age = 56 THEN 'ccc', 'ddd'
WHEN age = 78 THEN 'eee', 'fff'
ELSE first_name, last_name
END
-----------------------------------------------Can you give an example of a nested decode statement.
test@ora>
test@ora>
test@ora> --
test@ora> drop table t;
Table dropped.
test@ora> create table t as
2 select rownum x, cast(null as varchar2(10)) y from all_objects
3 where rownum <= 10;
Table created.
test@ora>
test@ora> select x, y from t;
X Y
1
2
3
4
5
6
7
8
9
10
10 rows selected.
test@ora>
test@ora> -- You want to change the values of y to 'a' through 'j' for x = 1 through 10
test@ora> -- and y = 'X' otherwise
test@ora> --
test@ora> -- Let's say the limit on the number of components were 12
test@ora> -- Then your decode statement would've been:
test@ora> --
test@ora> update t
2 set y = decode(x,
3 1, 'a',
4 2, 'b',
5 3, 'c',
6 4, 'd',
7 5, 'e',
8 'f');
10 rows updated.
test@ora>
test@ora>
test@ora> select x, y from t;
X Y
1 a
2 b
3 c
4 d
5 e
6 f
7 f
8 f
9 f
10 f
10 rows selected.
test@ora>
test@ora> -- As you can see you are unable to:
test@ora> --
test@ora> -- change y to 'g' if x = 7
test@ora> -- change y to 'h' if x = 8
test@ora> -- change y to 'i' if x = 9
test@ora> -- change y to 'j' if x = 10
test@ora> -- change y to 'X' otherwise
test@ora> --
test@ora>
test@ora> -- What you would do then is -
test@ora> -- (i) Let the 11 components remain as they are and
test@ora> -- (ii) Introduce a nested decode function *AS THE 12TH COMPONENT*
test@ora> --
test@ora>
test@ora> rollback;
Rollback complete.
test@ora>
test@ora> --
test@ora> update t
2 set y = decode(x,
3 1, 'a',
4 2, 'b',
5 3, 'c',
6 4, 'd',
7 5, 'e',
8 decode(x,
9 6, 'f',
10 7, 'g',
11 8, 'h',
12 9, 'i',
13 10, 'j',
14 'X')
15 );
10 rows updated.
test@ora>
test@ora> select x, y from t;
X Y
1 a
2 b
3 c
4 d
5 e
6 f
7 g
8 h
9 i
10 j
10 rows selected.
test@ora>
test@ora>HTH
isotope
Extrapolate that to 255 components and you get 254 + 255 = 509 components. And so on...
Message was edited by:
isotope -
Using a Switch statement for Infix to Prefix Expressions
I am stuck on the numeric and operator portion of the switch statement...I have the problem also figured out in an if/else if statement and it works fine, but the requirements were for the following algorithm:
while not end of expression
switch next token of expression
case space:
case left parenthesis:
skip it
case numeric:
push the string onto the stack of operands
case operator:
push the operator onto the stack of operators
case right parenthesis:
pop two operands from operand stack
pop one operator from operator stack
form a string onto operand stack
push the string onto operand stack
pop the final result off the operand stack
I know that typically case/switch statement's can only be done via char and int's. As I said I am stuck and hoping to get some pointers. This is for a homework assignment but I am really hoping for a few pointers. I am using a linked stack class as that was also the requirements. Here is the code that I have:
import java.io.*;
import java.util.*;
import java.lang.*;
/*--------------------------- PUBLIC CLASS INFIXTOPREFIX --------------------------------------*/
/*-------------------------- INFIX TO PREFIX EXPRESSIONS --------------------------------------*/
public class infixToPrefix {
private static LinkedStack operators = new LinkedStack();
private static LinkedStack operands = new LinkedStack();
// Class variable for keyboard input
private static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
// Repeatedly reads in infix expressions and evaluates them
public static void main(String[] args) throws IOException {
// variables
String expression, response = "y";
// obtain input of infix expression from user
while (response.charAt(0) == 'y') {
System.out.println("Enter a parenthesized infix expression."); // prompt the user
System.out.println("Example: ( ( 13 + 2 ) * ( 10 + ( 8 / 3 ) ) )");
System.out.print("Or as: ((13+2)*(10+(8/3))): ");
expression = stdin.readLine(); // read input from the user
// output prefix expression and ask user if they would like to continue
System.out.println("The Prefix expression is: " + prefix(expression)); // output expression
System.out.println("Evaluate another? y or n: "); // check with user for anymore expressions
response = stdin.readLine(); // read input from user
if (response.charAt(0) == 'n') { // is user chooses n, output the statement
System.out.println("Thank you and have a great day!");
} // end if statement
} // end while statement
} // end method main
/*------------- CONVERSION OF AN INFIX EXPRESSION TO A PREFIX EXPRESSION ------------*/
/*--------------------------- USING A SWITCH STATEMENT ------------------------------*/
private static String prefix(String expression) {
// variables
String symbol, operandA, operandB, operator, stringA, outcome;
// initialize tokenizer
StringTokenizer tokenizer = new StringTokenizer(expression, " +-*/() ", true);
while (tokenizer.hasMoreTokens()) {
symbol = tokenizer.nextToken(); // initialize symbol
switch (expression) {
case ' ':
break; // accounting for spaces
case '(':
break; // skipping the left parenthesis
case (Character.isDigit(symbol.charAt(0))): // case numeric
operands.push(symbol); // push the string onto the stack of operands
break;
case (!symbol.equals(" ") && !symbol.equals("(")): // case operator
operators.push(symbol); // push the operator onto the stack of operators
break;
case ')':
operandA = (String)operands.pop(); // pop off first operand
operandB = (String)operands.pop(); // pop off second operand
operator = (String)operators.pop(); // pop off operator
stringA = operator + " " + operandB + " " + operandA; // form the new string
operands.push(stringA);
break;
} // end switch statement
} // end while statement
outcome = (String)operands.pop(); // pop off the outcome
return outcome; // return outcome
} // end method prefix
} // end class infixToPrefixAny help would be greatly appreciated!so, i did what flounder suggested:
char e = expression.charAt(0);
while (tokenizer.hasMoreTokens()) {
symbol = tokenizer.nextToken(); // initialize symbol
switch (e) {
case ' ':
break; // accounting for spaces
case '(':
break; // skipping the left parenthesis
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
operands.push(symbol); // push the string onto the stack of operands
break; // case numeric
case '+':
case '-':
case '*':
case '/':
operators.push(symbol); // push the operator onto the stack of operators
break; // case operator
case ')':
operandA = (String)operands.pop(); // pop off first operand
operandB = (String)operands.pop(); // pop off second operand
operator = (String)operators.pop(); // pop off operator
stringA = operator + " " + operandB + " " + operandA; // form the new string
operands.push(stringA);
break;
default:
} // end switch statement
} // end while statement
outcome = (String)operands.pop(); // pop off the outcome
return outcome; // return outcomeafter this, I am able to compile the code free of errors and I am able to enter the infix expression, however, the moment enter is hit it provides the following errors:
Exception in thread "main" java.lang.NullPointerException
at LinkedStack$Node.access$100(LinkedStack.java:11)
at LinkedStack.pop(LinkedStack.java:44)
at infixToPrefix.prefix(infixToPrefix.java:119)
at infixToPrefix.main(infixToPrefix.java:59)
Any ideas as to why? I am still looking through seeing if I can't figure it out, but any suggestions? Here is the linked stack code:
public class LinkedStack {
/*--------------- LINKED LIST NODE ---------------*/
private class Node {
private Object data;
private Node previous;
} // end class node
/*-------------- VARIABLES --------------*/
private Node top;
/*-- Push Method: pushes object onto LinkedStack --*/
public void push(Object data) {
Node newTop = new Node();
newTop.data = data;
newTop.previous = top;
top = newTop;
} // end function push
/*--- Pop Method: pop obejct off of LinkedStack ---*/
public Object pop() {
Object data = top.data;
top = top.previous;
return data;
} // end function pop
} // end class linked stackEdited by: drmsndrgns on Mar 12, 2008 8:10 AM
Edited by: drmsndrgns on Mar 12, 2008 8:14 AM
Edited by: drmsndrgns on Mar 12, 2008 8:26 AM
Maybe you are looking for
-
i have had my ipod for a few months its always worked fine then recently when pluged in to pc via usb2 it says on pc the usb devise you connected has malfunctioned and i can no longer transfer music to it. how can i fix this
-
Ever since i downloaded OSX Mountain Lion, Express VPN no longer works properly for me. Even though it says I am connected, webpages refuse to load. However, connection speed is fine when its turned off. I cannot go on many websites without the VPN.
-
OS X freezes whenever I cannot force quit an application
About twice a week I have an application that will hang. Usually when I close my MacBook Pro while the app is running. The app will not quit or force quit, if I try to restart the OS, it hangs and I have to hold the power button down to shut it off.
-
RfcAdapter-Reciver error in channel GeneratedReceiverChannel_RFC
Hi all, We had setup up ALM in XI/PI, sometime we receive alert with below content: Blank in below fields: SXMS_ERROR_CODE, SXMS_ERROR_CAT, SXMS_MSG_GUID SXMS_FROM_SERVICE, SXMS_FROM_INTERFACE, SXMS_TO_INTERFACE Have values in below fields: SXMS_TO_S
-
I just replaced a 3rd gen ipod with the new 60 gig color. The quick start guide instructs me to uninstall itunes and install the new software. Will i loose all of the playlists i have created on the old software if I do this, or does that file roll i