Unable to retreive the return value of pl/sql function using DB Adapter

Dear Experts,
I am using DB Adapter in my BPEL Process. Using DB Adapter I am invoking a PL / SQL function. I am able to send two input parameters for the pl/sql function. But I dont know how to retrieve the return value from the function. Please suggest me.
Thanks,
Rajesh

Yes I am returning a value from PL/SQL function.
Please see the code segments below,
FUNCTION "TD_INSERT" (a TDINIT_TYPE, stops TDDETAIL_TABLE )
RETURN VARCHAR2
AS
td_no Number;
td_id Number;
stop TDDETAILFULL_TYPE;
length number;
BEGIN
insert into TD_INIT values( ----passing all the values here --------- );
select max(tdno) into td_no from TD_INIT ;
length := stops.count;
for i in 1.. length loop
stop := stops(i);
insert into TD_DETAIL_FULL values(
td_no, ------- );
end loop;
commit;
RETURN td_no;
END;
Thanks,
Rajesh

Similar Messages

  • How to get the return value of a LOV item using javascript

    Hello,
    I am trying to put an onchange attribute in the HTML Form Element Attributes field of a LOV item. The javascript should access the new return value of the item. How is this done ? All the methods I have tried give only the display value, not the return value. For example $v() returns the display value.
    Tiina

    If your item is called P1_ITEM this will give you the return value of a popup (displays description,returns key value)
    alert($x('P1_ITEM_HIDDENVALUE').value)
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • Get the return value of an RFC function / BAPI

    Hello,
    I'm a Web Dynpro Java beginner and I try to get the return value (domain: NUMC6) of an RFC function without success.
    Here is what I do, could you please tell me what is wrong?
    First, here is my context:
    Context
    |
    |---- ZMy_Bapi
         |
         |---- MyOutputResult
         |     |
         |     |---- MyReturnValue
         |
         |---- MyInput
    My model:
    MyModel
    |
    |---- ZMy_Bapi_Input
         |
         |---- Output
         |     |
         |     |---- ZMy_Bapi_Output
         |          |
         |          |---- Return_Value
         |
         |---- Input_Value
    The mapping between them:
    - MyInput is mapped to Input_Value
    - MyReturnValue is mapped to Return_Value
    And my code:
    ZMy_Bapi_Input bapiInput = new ZMy_Bapi_Input();
    wdContext.nodeZMy_Bapi().bind(bapiInput);
    bapiInput.setInput_Value("A value");
    executeZMy_Bapi();
    ZMy_Bapi_Output bapiOutput = new ZMy_Bapi_Output();
    wdContext.nodeMyOutputResult().bind(bapiOutput);
    IMyOutputResultElement outputElement = wdContext.nodeMyOutputResult().currentMyOutputResultElement();
    String result = outputElement.getMyReturnValue();
    Finally, here is the code of the executeZMy_Bapi() function:
    try {
         wdContext.currentZMy_BapiElement().modelObject().execute();
         wdContext.nodeMyOutputResult().invalidate();
    } catch (Exception ex) {
         ex.printStackTrace();
    My problem is that "result" keeps being empty
    Thanks in advance for your help!

    It still doesn't work, I'm gonna turn crazy!
    But there is one good point: I get the method you mentioned: getZMy_Bapi_OutputElementAt and getMyReturnValue without casting, just as you said first.
    Here are the updated context, model, mapping and code.
    Context:
    MyContext
    |
    |---- ZMy_Bapi
         |
         |---- MyOutputResult
         |     |
         |     |---- ZMy_Bapi_Output
         |          |
         |          |---- MyReturnValue
         |
         |---- MyInput
    Model:
    MyModel
    |
    |---- ZMy_Bapi_Input
    |     |
    |     |---- Output
    |     |     |
    |     |     |---- ZMy_Bapi_Output
    |     |          |
    |     |          |---- Return_Value
    |     |
    |     |---- Input_Value
    |
    |
    |---- ZMy_Bapi_Output
         |
         |---- Return_Value
    Mapping
    ZMy_Bapi     --> ZMy_Bapi_Input
    MyOutputResult     --> Output
    ZMy_Bapi_Output     --> ZMy_Bapi_Output
    MyReturnValue     --> Return_Value
    MyInput          --> Input_Value
    Code
    ZMy_Bapi_Input bapiInput = new ZMy_Bapi_Input();
    wdContext.nodeZMy_Bapi().bind(bapiInput);
    bapiInput.setInput_Value("A value");
    executeZMy_Bapi();
    ZMy_Bapi_Output bapiOutput = new ZMy_Bapi_Output();
    wdContext.nodeMyOutputResult().bind(bapiOutput);
    String result = "";
    for (int i = 0; i < wdContext.nodeZMy_Bapi_Output().size(); i++) {
         IZMy_Bapi_OutputElement resultElem = wdContext.nodeZMy_Bapi_Output().getZMy_Bapi_OutputElementAt(i);
         if (resultElem.getMyReturnValue() != "" && resultElem.getMyReturnValue() != null) {
              result = resultElem.getMyReturnValue();
    Edited by: Franis Pignon on Oct 17, 2008 11:16 PM

  • How to exit from SQL*Plus based on the return value of a SQL select stment?

    Hi
    I have a SQL script executed from SQL*Plus. I would like to know if SQL*Plus
    supports any kind of branching or exiting from script execution based on a
    returned value of a SQL select statement. I am on 9i.
    Regards,
    Tamas Szecsy

    in sqlplus, you have whenever
    ex:
    whenever sqlerror exit failure
    insert into ...
    -- if this fails, then you will be out
    insert into ...
    -- if this fails, then you will be out
    whenever sqlerror continue
    insert into ...
    -- if this fails, this continues
    insert into ...and you have PL/SQL
    declare x number;
    begin
    select count(*) into x from emp;
    if (x=14) then null; end if;
    end;
    /note that you can mix those in some case
    -- exit if there is no row in emp
    whenever sqlerror exit 1
    var dummy number
    exec select count(*) into :dummy from emp having count(*)!=0

  • Return the two values in PL/SQL function

    Hi,
    How to create the PL/SQL function to return two values based on arguments?
    Can anyone suggest me the idea?
    TIA,

    Dhiva wrote:
    How to create the PL/SQL function to return two values based on arguments?A function can return only a single "+thing+".
    That thing can be a scalar value (single value). Such as date, number or string. E.g.
    create or replace function F... return number is ..That thing can be a non-scalar value (array). E.g.
    create or replace type TNumberArray is table of numbner;
    create or replace function F... return TNumberArray is ..That thing can be a complex scalar structure (record/object type) E.g.
    create or replace function F... return EMP%RowType is ..That thing can be a complex non-scalar structure (array of object/record types). E.g.
    create object TNameValue is object(
      name varchar2(30),
      value varchar2(4000)
    create or replace TNameValueArray is table of TNameValue;
    create or replace function F... return TNameValue is ..The bottom line is think structured data. A function can return a single variable. But that variable can (and should be) a proper structured data variable - and can be complex and can be non-scalar.

  • Getting Excel to interpret the return string of a WEBSERVICE() function using a WCF REST service.

    I am using the WEBSERVICE() function in Excel and a WCF REST service is called through this function.  
    The web service returns a string value of true or false when invoked.  E.g. <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">True</string>
    This has been confirmed through debugging and it seems to be working fine when invoked through a client application or browser.
    However, the result shown in the cell in the Excel sheet is #VALUE!. This particular cell has a custom format (set using the Format Cells ... option) that displays "Yes" or "No". (The
    custom format is "Yes" ; "Yes" ; "No".)  Is this the correct way of interpreting the results of a Web Service method called in Excel? Does a #VALUE! result actually imply a formatting issue or some other interpretation
    error? Is there anything missing? Can somebody suggest ideas?
    Any help would be appreciated.
    Many thanks,
    Keith
    R K Howard

    Hi Keith,
    Have you used the formula FILTERXML(xml, xpath) function to extract single pieces of data from the XML string?
    If not, please follow the blog below, the author will guide you to get data from Webservice.
    http://blogs.office.com/2013/03/21/use-webservice-functions-to-automatically-update-excel-2013-spreadsheets-with-online-data/
    Best Regards
    Lan 
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Building the varchar string to return from a pl sql function

    i'm new with pl/sql and i'm having trouble trying to build the string that i want to return from a function that is inside a package. it seems my problem stems from the fact that i'm trying to incorporate a variable (varchar2) into the string to be returned. below are two attempts that i've made which do not work:
    function test_policy (p_schema_name IN varchar2, p_object_name IN varchar2) return varchar2 as
    predicate_value varchar2(2000);
    user_name varchar2(100);
    begin
    select first_name
    into user_name
    from employees
    where first_name = SYS_CONTEXT('hr_app_context', 'username');
    predicate_value := 'first_name = ' || user_name;
    predicate_value := 'first_name = ' || '' || user_name || '';
    return predicate_value;
    end test_policy;
    Can someone help me with the proper syntax to build my string for the return value? Thanks.

    this function implements the code for a policy i've created. basically, the policy says that when i do a select on the employees table, i should only see a record whose first_name = sys_context('hr_app_context', 'username'). so, when i perform a simple select * from employees, i get an error which says policy predicate has error. i'm pretty sure the error is caused by how i'm building the return value for that function. if i hard code some return value like:
    predicate_value := 'first_name = ''HR''' ;
    the select statement above works fine, and i only see the record from employees where first_name = 'HR'

  • Unable to set the selected value for a ADF LOV

    Hi,
    I am developing an application using jdeveloper 10.1.3 and Struts.
    I have created a ADF LOV on my JSP Page as given below:
    <html:select property="lob" onchange="javascript:selectLOB(this.form)">
    <html:optionsCollection label="prompt" value="index" property="lob.displayData"/>
    </html:select>
    When i submit the form, i am able to get the value of the selected Value in the List.
    JUCtrlListBinding listBinding = (JUCtrlListBinding) formBean.get("Lob");
    Row r = (Row) listBinding.getSelectedValue();
    String SoLob = (String) r.getAttribute("LobLob");
    But i am unable to set the selected value back in the list when i return to the form again.
    I tried the following:
    int x = listBinding.getSelectedIndex();
    listBinding.setSelectedIndex(x);
    It would be really helpful if some one could let me know what needs to be done.
    Thanks,
    Subashini

    Gyan,
    I tried with the code you suggest , its trying to set the value of a field, but my requirement is to change the property for
    "Rendered" on the field so that based on search parameters we can hide result table column.
    After searching online, I modified the controller code as follows
    1.Created a new transient attribute (Testrender) with type "Boolean" and always updateable.
    2.changed the "Rendered" property value on the field I want to hide as ${oa.PoSearchVO1.Testrender}.
    3. Modified the controller code as follows :
            OAApplicationModule am = pageContext.getApplicationModule(webBean);
            OAViewObject testvo = (OAViewObject)am.findViewObject("PoSearchVO1");
            OADBTransaction txn = am.getOADBTransaction();
            if (testvo != null)
              OARow row = (OARow)testvo.first();
                if (a.equalsIgnoreCase("Approved"))
                     row.setAttribute("Testrender", Boolean.FALSE);
                else
                     row.setAttribute("Testrender", Boolean.TRUE);
            } But now when i run the page and populate the search field and click "Go" its hiding the field but throwing the following error and the search results are also bad.
    Its using only the value of one search parameter but not the second one .
    The search cannot be executed because the table has pending changes that would be lost. I think the vo is getting dirty when I update the transient attribute value. So I used txn.rollback ,then search is working fine but its not hiding the field.
    So can you please let me know how to proceed from here ?

  • LDAP Connection exception: unable to retreive the specified realm(s).

    I am using Embedded OC4J and I have a web form based authentication (j_security _check) and configured my orion-application.xml to use LDAP connection in this way:
    <?xml version = '1.0' encoding = 'windows-1252'?>
    <orion-application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/orion-application-10_0.xsd">
    <jazn provider="LDAP" location="ldap://192.168.1.114:389"
    default-realm="cn" jaas-mode="doAsPrivileged"/>
    <jazn-loginconfig>
    <application>
    <name>ceads</name>
    <login-modules>
    <login-module>
    <class>oracle.security.jazn.login.module.LDAPLoginModule</class>
    <control-flag>required</control-flag>
    <options>
    <option>
    <name>oracle.security.jaas.ldap.connect.pool.prefsize</name>
    <value>10</value>
    </option>
    ....... other LDAp parameters ...
    When I try to log in, is always failed and I get this exception. I have no Idea what to do.
    javax.security.auth.login.LoginException: oracle.security.jazn.JAZNException: The system is unable to retreive the specified realm(s).
    at oracle.security.jazn.spi.ldap.LDAPRealmManager.searchRealms(LDAPRealmManager.java:1194)
    at oracle.security.jazn.spi.ldap.LDAPRealmManager.getRealm(LDAPRealmManager.java:238)
    at oracle.security.jazn.login.module.RealmLoginModule.getRealmFromUsername(RealmLoginModule.java:247)
    at oracle.security.jazn.login.module.RealmLoginModule.getRealm(RealmLoginModule.java:219)
    at oracle.security.jazn.login.module.RealmLoginModule.getRealmUser(RealmLoginModule.java:198)
    at oracle.security.jazn.login.module.RealmLoginModule.authenticate(RealmLoginModule.java:111)
    at oracle.security.jazn.login.module.RealmLoginModule.authenticate(RealmLoginModule.java:86)
    at oracle.security.jazn.login.module.AbstractLoginModule.login(AbstractLoginModule.java:265)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at javax.security.auth.login.LoginContext.invoke(LoginContext.java:769)
    at javax.security.auth.login.LoginContext.access$000(LoginContext.java:186)
    at javax.security.auth.login.LoginContext$4.run(LoginContext.java:683)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680)
    at javax.security.auth.login.LoginContext.login(LoginContext.java:579)
    at oracle.security.jazn.oc4j.OC4JUtil.doJAASLogin(OC4JUtil.java:241)
    at oracle.security.jazn.oc4j.GenericUser$1.run(JAZNUserManager.java:818)
    at oracle.security.jazn.oc4j.OC4JUtil.doWithJAZNClsLdr(OC4JUtil.java:173)
    at oracle.security.jazn.oc4j.GenericUser.authenticate(JAZNUserManager.java:814)
    at oracle.security.jazn.oc4j.FilterUser.authenticate(JAZNUserManager.java:1143)
    at com.evermind.server.http.EvermindHttpServletRequest.checkAndSetRemoteUser(EvermindHttpServletRequest.java:3760)
    at com.evermind.server.http.EvermindHttpServletRequest.getUserPrincipalInternal(EvermindHttpServletRequest.java:3727)
    at com.evermind.server.http.HttpApplication.checkAuthenticationAndAuthorize(HttpApplication.java:6350)
    at com.evermind.server.http.HttpApplication.getRequestDispatcher(HttpApplication.java:3030)
    at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:738)
    at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
    at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:221)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:122)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:111)
    at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
    at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:234)
    at oracle.oc4j.network.ServerSocketAcceptHandler.access$700(ServerSocketAcceptHandler.java:29)
    at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:879)
    at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
    at java.lang.Thread.run(Thread.java:595)
    Caused by: java.lang.IllegalStateException: LDAP properties not properly defined. Please check your JAZN configuration.
    at oracle.security.jazn.spi.ldap.LDAPContext.getDirContext(LDAPContext.java:476)
    at oracle.security.jazn.spi.ldap.LDAPContext.getDefaultDirContext(LDAPContext.java:246)
    at oracle.security.jazn.spi.ldap.LDAPContext.getOrclRootCtxDN(LDAPContext.java:187)
    at oracle.security.jazn.spi.ldap.LDAPContext.getSiteJAZNCtxDN(LDAPContext.java:222)
    at oracle.security.jazn.spi.ldap.LDAPRealmManager.searchRealms(LDAPRealmManager.java:1087)
    ... 37 more
    Edited by: user6112181 on 15-oct-2010 19:30
    Edited by: user6112181 on 15-oct-2010 19:31

    Hi,
    Can you access the URL using a browser? Does it work with the credentials used for the RunAs account?
    Strange error message though - are the account you are running the console with, present in the SCSM CMDB?
    Regards
    //Anders
    Anders Asp | Lumagate | www.lumagate.com | Sweden | My blog: www.scsm.se

  • How to get the return values from a web page

    Hi all :
       how to get the return values from a web page ?  I mean how pass values betwen webflow and web page ?
    thank you very much
    Edited by: jingying Sony on Apr 15, 2010 6:15 AM
    Edited by: jingying Sony on Apr 15, 2010 6:18 AM

    Hi,
    What kind of web page do you have? Do you have possibility to for example make RFCs? Then you could trigger events (with parameters that could "return" the values) and the workflow could react to those events. For example your task can have terminating events.
    Regards,
    Karri

  • Remote Object - not able to get the returned value from java method

         Hi ,
    I am developing one sample flex aplication that connects to the java code and displays the returned value from the
    java method in flex client. Here I am able to invoke the java method but not able to collect the returned value.
    lastResult is giving null .  I am able to see the sysout messages in server console.
    I am using flex 3.2 and blazeds server  and java 1.5
    Here is the code what I have written.
    <?xml version="1.0" encoding="utf-8"?><mx:WindowedApplication  xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#FFFFFF" initialize="initApp()">
     <mx:Script><![CDATA[
    import mx.controls.Alert; 
    import mx.binding.utils.ChangeWatcher; 
    import mx.rpc.events.ResultEvent; 
    import mx.messaging.*; 
    import mx.messaging.channels.* 
    public function initApp():void { 
         var cs:ChannelSet = new ChannelSet(); 
         var customChannel:Channel = new AMFChannel("my-amf", "http://localhost:8400/blazeds/messagebroker/amf");     cs.addChannel(customChannel);
         remoteObj.channelSet = cs;
    public function writeToConsole():void {      remoteObj.writeToConsole(
    "hello from Flash client");
          var returnedVal:String = remoteObj.setName().lastResult;     Alert.show(returnedVal);
    //[Bindable] 
    // private var returnedVal:String; 
    ]]>
    </mx:Script>
    <mx:RemoteObject id="remoteObj" destination="sro" /> 
    <mx:Form width="437" height="281">
     <mx:FormItem>  
    </mx:FormItem>  
    <mx:Button label="Write To Server Console" click="writeToConsole()"/>
     </mx:Form>
     </mx:WindowedApplication>
    Java code
    public  
         public SimpleRemoteObject(){  
              super();     }
      class SimpleRemoteObject { 
         public void writeToConsole(String msg) {          System.out.println("SimpleRemoteObject.write: " + msg);     }
         public String setName(){          System.
    out.println("Name changed in Java"); 
              return "Name changed in Java";
    And I have configured destination in  remote-config.xml
    <destination id="sro">
       <properties>    
        <source>SimpleRemoteObject</source>
        <scope>application</scope>
       </properties>
      </destination>
    Please help me .

    You are not able to get the returned value because if you see the Remote object help you will realise you have to use result="resultfn()" and fault = "faultfn()"
    In this you define what you wish to do.
    More importantly in the remote object you need to define which method you wish to call using the method class like this
    <mx:RemoteObject id="remoteObj" destination="sro" result="r1" fault="f1"  >
         <Method name="javaMethodName" result="r2" fault="f2"/>
    <mx:RemoteObject>
    r2 is the function where you get the result back from java and can use it to send the alert.

  • How can I use comma in the return values of a static list of values

    Hi all,
    I want to create a select list (static LOV) like the following:
    Display Value / Return Value
    both are "Y" / 'YY'
    one is "Y" / 'YN','NY'
    I write the List of values definition is like this:
    STATIC:both are "Y"; 'YY',one is "Y";'YN', 'NY'
    However, it is explain by htmldb like this:
    Display Value / Return Value
    both are "Y" / 'YY'
    one is "Y" / 'YN'
    / 'NY'
    I tried using "\" before the ",", or using single or double quote, but all these do not work:(
    How can I use a comma in the return values?
    Thanks very much!

    "Better still, why not process the code of both Y with 2Y and one is Y with 1Y? "
    Could you please explain in detail? thanks! I am quite new to htmldb
    In fact I have a table which has too columns "a1" and "a2", both the values of these two columns are "Y" or "N". AndI want to choose the records that both a1 and a2 are "Y", or just one of a1, a2 is "Y".
    So I write the report sql like this:
    "select * from t1 where a1 || a2 in(:MYSELECTLIST) "
    Thus, I need to use "," in the LOV, since expression list in IN(,,,) using ",".
    Any other way to implement this?

  • How to Change the return value for the parameters

    Hi, Can anyone help me with my problem?
    I have a parameter called "P1_Projects" defined in the HTMLDB page, on the report region, there are 2 buttons, one is "Go" button to submit the report on the screen, so user can preview the report, then another button "Export to PDF" can be clicked to generate the report using Oracle Report Services. The "Export to PDF" button will use the same set of parameters submitted for the "Go" button.
    So, the parameter "P1_Projects" is being used by these 2 buttons. and I have to pass a "%" wild card for "All Projects". To make the "Export to PDF" button work, I have to safe encode the return value for "%" to "%25" in order to pass the URL formula, but now my "Go" button doesn't work with "%25", it only recognize the "%" wild card.
    Is there a way to conditionally change the value depends which button is clicked?
    Any hint or help is highly appreciated!
    Hong

    try creating a plsql process which sets the P1_Projects item as required.
    in the plsql you can do:
    if :REQUEST = 'GO' then
    xxx
    else
    xxxx
    end if;
    set the condition to plsql expression:
    :REQUEST in ('GO', 'EXPORT')
    NB. the request value is usually set to the button name when a page is submitted from a button

  • Job scheduling error : The return value was unknown. The process exit code was -1073741819. The step failed.

    I am working in Sqlserver 2008 R2, SSIS 64 bit version
    I am getting the below  error while scheduling the job in the development server  Database. 
    The return value was unknown.  The process exit code was -1073741819.  The step failed.
    The SSIS front end execution runs fine.
    Have anyone  faced this issue before?

    Hi Venkat,
    If you already changed to 64bit and still doesn't work then create proxy account.. 
    To create a proxy account
    In Object Explorer, expand a server.
    Expand SQL Server Agent.
    Right-click Proxies and select New Proxy.
    On the General page of the New Proxy Account dialog, specify the proxy name, credential name, and
    description for the new proxy. Note that you must create a credential first before you create a proxy if one is not already available. For more information about creating a credential, see How
    to: Create a Credential (SQL Server Management Studio) or CREATE CREDENTIAL (Transact-SQL).
    Check the appropriate subsystem for this proxy.
    On the Principals page, add or remove logins or roles to grant or remove access to the proxy account.
    Thanks

  • Getter/setter methods -- how do I use the return values

    I'm just learning Java, and I haven't been to this site since the end of July, I think. I have a question regarding getter and setter methods. I switched to the book Head First Java after a poster here recommended it. I'm only about a hundred pages into the book, so the code I'm submitting here reflects that. It's the beginnings of a program I'd eventually like to complete that will take the entered information of my CD's and alphabetize them according to whatever criteria I (or any user for that matter) choose. I realize that this is just the very beginning, and I don't expect to have the complete program completed any time soon -- it's my long term goal, but I thought I could take what I'm learning in the book and put it to practical use as I go along (or at lest try to).
    Yes I could have this already done it Excel, but where's the fun and challenge in that? :) Here's the code:
    // This program allows the user to enter CD information - Artist name, album title, and year of release -- and then organizes it according the the user's choice according to the user's criteria -- either by artist name, then title, then year of release, or by any other order according to the user's choice.
    //First, the class CDList is created, along with the necessary variables.
    class CDList{
         private String artistName;//only one string for the artist name -- including spaces.
         private String albumTitle;//only one string the title name -- including spaces.
         private int yearOfRelease;
         private String recordLabel;
         public void setArtistName(String artist){
         artistName = artist;
         public void setAlbumTitle(String album){
         albumTitle = album;
         public void setYearOfRelease(int yor){
         yearOfRelease = yor;
         public void setLabel(String label){
         recordLabel = label;
         public String getArtistName(){
         return artistName;
         public String getAlbumTitle(){
         return albumTitle;
         public int getYearOfRelease(){
         return yearOfRelease;
        public String getLabel(){
        return recordLabel;
    void printout () {
           System.out.println ("Artist Name: " + getArtistName());
           System.out.println ("Album Title: " + getAlbumTitle());
           System.out.println ("Year of Release: " + getYearOfRelease());
           System.out.println ("Record Label: " + getLabel());
           System.out.println ();
    import static java.lang.System.out;
    import java.util.Scanner;
    class CDListTestDrive {
         public static void main( String[] args ) {
              Scanner s=new Scanner(System.in);
              CDList[] Record = new CDList[4];
              int x=0;     
              while (x<4) {
              Record[x]=new CDList();
              out.println ("Artist Name: ");
              String artist = s.nextLine();
              Record[x].setArtistName(artist);
              out.println ("Album Title: ");
              String album = s.nextLine();
              Record[x].setAlbumTitle(album);
              out.println ("Year of Release: ");
              int yor= s.nextInt();
                    s.nextLine();
              Record[x].setYearOfRelease(yor);
              out.println ("Record Label: ");
              String label = s.nextLine();
              Record[x].setLabel(label);
              System.out.println();
              x=x+1;//moves to next CDList object;
              x=0;
              while (x<4) {
              Record[x].getArtistName();
              Record[x].getAlbumTitle();
              Record[x].getYearOfRelease();
              Record[x].getLabel();
              Record[x].printout();
              x=x+1;
                   out.println("Enter a Record Number: ");
                   x=s.nextInt();
                   x=x-1;
                   Record[x].getArtistName();
                Record[x].getAlbumTitle();
                Record[x].getYearOfRelease();
                Record[x].getLabel();
                Record[x].printout();
         }//end main
    }//end class          First, I'd like to ask anyone out there to see if I could have written this any more efficiently, with the understanding that I'm only one hundred pages into the book, and I've only gotten as far as getter and setter methods, instance variables, objects and methods. The scanner feature I got from another book, but I abandoned it in favor of HFJ.
    Secondly --
    I'm confused about getter and setter methods -- I'd like someone to explain to me what they are used for exactly and the difference between the two. I have a general idea, that getters get a result from the method and setters set or maybe assign a value to variable. I submitted this code on another site, and one of the responders told me I wasn't using the returned values from the getter methods (he also told me about using a constructor method, but I haven't got that far in the book yet.). The program compiles and runs fine, but I can't seem to figure out how I'm not using the returned values from the getter methods. Please help and if you can explain in 'beginners terms,' with any code examples you think are appropriate. It will be greatly appreciated.
    By the way, I'm not a professional programmer -- I'm learning Java because of the intellectual exercise and the fun of it. So please keep that in mind as well.
    Edited by: Straitsfan on Sep 29, 2009 2:03 PM

    Straitsfan wrote:
    First, I'd like to ask anyone out there to see if I could have written this any more efficiently, with the understanding that I'm only one hundred pages into the book, and I've only gotten as far as getter and setter methods, instance variables, objects and methods. The scanner feature I got from another book, but I abandoned it in favor of HFJ.Yes, there is tons you could have done more efficiently. But this is something every new programmer goes through, and I will not spoil the fun. You see, in 3 to 6 months when you have learned much more Java, assuming you stick with it, you will look back at this and be like "what the hell was I thinking" and then realize just haw far you have come. So enjoy that moment and don't spoil it now by asking for what could have been better/ more efficient. If it works it works, just be happy it works.
    Straitsfan wrote:
    Secondly --
    I'm confused about getter and setter methods -- I'd like someone to explain to me what they are used for exactly and the difference between the two. I have a general idea, that getters get a result from the method and setters set or maybe assign a value to variable. I submitted this code on another site, and one of the responders told me I wasn't using the returned values from the getter methods (he also told me about using a constructor method, but I haven't got that far in the book yet.). The program compiles and runs fine, but I can't seem to figure out how I'm not using the returned values from the getter methods. Please help and if you can explain in 'beginners terms,' with any code examples you think are appropriate. It will be greatly appreciated.
    By the way, I'm not a professional programmer -- I'm learning Java because of the intellectual exercise and the fun of it. So please keep that in mind as well.First, if you posted this somewhere else you should link to that post, it is good you at least said you did, but doubleposting is considered very rude because what inevitably happens in many cases is the responses are weighed against each other. So you are basically setting anyone up who responds to the post for a trap that could make them look bad when you double post.
    You are setting you getters and setters up right as far as I can tell. Which tells me that I think you grasp that a getter lets another class get the variables data, and a setter lets another class set the data. One thing, be sure to use the full variable name so you should have setRecordLabel() and getRecodLabel() as opposed to setLabel() and getLabel(). Think about what happens if you go back and add a label field to the CDList class, bad things the way you have it currently. Sometimes shortcuts are not your friend.
    And yes, you are using the getters all wrong since you are not saving off what they return, frankly I am suprised it compiles. It works because you don't really need to use the getters where you have them since the CDList Record (should be lowercase R by the way) object already knows the data and uses it in the printout() method. Basically what you are doing in lines like:
    Record[x].getArtistName();is asking for the ArtistName in Record[x] and then getting the name and just dropping it on the floor. You need to store it in something if you want to keep it, like:
    String artistName = Record[x].getArtistName();See how that works?
    Hope this helped, keep up the good learning and good luck.
    JSG

Maybe you are looking for