How to start with the Data Access Object Pattern

I have about a years experience with regular java/UML. I would like to understand the DAO Pattern and have therefore read :
http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
But I don't understand much of it. What do I need to know before/read/code before I can understand DAO?

I've never used J2EE but that came across pretty quick to me mostly because I've pondered that pattern in designing my own little toy webapp with database.
What part didn't you understand?

Similar Messages

  • Best Practice Using Data Access Object Pattern

    I was wondering what would be the best approach with regards to implementing the Data Access Object pattern:
    Given the following database tables:
    teacher {teacher_id, teacher_name, ...}
    subject {subject_id, subject_name, ...}
    teacher_subject {teacher_id, subject_id}where teacher and subject hold details on teachers and subjects respectively and teacher_subject links teachers with the subjects that they currently teach, would I be better off:
    1) implementing three distinct DAO classes i.e. TeacherDAO, SubjectDAO, TeacherSubjectDAO, that correspond to each database table;
    2) implementing a single DAO class that controls access to all three tables, given that business operations often rely on access to all three tables e.g. getSubjectTeachers(Subject s), assignSubjectToTeacher(Subject s, Teacher t), getSubjectsTaughtBy(Teacher t)...
    Thanks
    Ian

    ...would I be better off:Depends on the system.
    If you are always going to have a teacher with subjects then all you need is one class.
    If on the other hand sometimes you are going to have subjects with teachers (given that you have a link table a many to many relationship exists) then two DAOs would exist.
    It would be unlikely for you to have a DAO for the link table unless perhaps you are anticipating a teacher having tens of thousands of subjects or one subject having tens of thousands of teachers.

  • Data access object pattern

    Hello,
    I am trying to implement the Data Access Object pattern and I have the following bean:
    package com.netpepper.ecards;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import javax.faces.application.Action;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    * @author Julien Martin
    * Card class: represents the card sent from a member of the public (the sender)
    * to another member of the public (the recipient).
    public class Card {
         private static Log log = LogFactory.getLog(Card.class);
         private long id;
         private String from_email;
         private String to_email;
         private String image;
         private String bgcolor;
         private String font;
         private String from_name;
         private String to_name;
         private String message;
         private String title;
         private boolean received;
         private boolean sent;
         private String send_date;
         private String response;
          * Public empty no-arg constructor
         public Card() {}
          * Full-fledged constructor
         public Card(
              long id,
              String from_email,
              String to_email,
              String image,
              String bgcolor,
              String font,
              String from_name,
              String to_name,
              String message,
              String title,
              boolean received,
              boolean sent,
              String send_date) {
              setId(id);
              setFrom_email(from_email);
              setTo_email(to_email);
              setImage(image);
              setBgcolor(bgcolor);
              setFont(font);
              setFrom_name(from_name);
              setTo_name(to_name);
              setMessage(message);
              setTitle(title);
              setReceived(received);
              setSent(sent);
              setSend_date(send_date);
          * @return the background color choosed by the sender.
         public String getBgcolor() {
              return bgcolor;
          * @return the font choosed by the sender.
         public String getFont() {
              return font;
          * @return the sender's email.
         public String getFrom_email() {
              return from_email;
          * @return the sender's name.
         public String getFrom_name() {
              return from_name;
          * @return the card's id.
         public long getId() {
              return id;
          * @return the image choosed by the sender.
         public String getImage() {
              return image;
          * @return the message input by the sender.
         public String getMessage() {
              return message;
          * @return <code>true</code> if the card has been received, <code>false</code> otherwise.
         public boolean isReceived() {
              return received;
          * @return <code>true</code> if the card has been sent, <code>false</code> otherwise.
         public boolean isSent() {
              return sent;
          * @return the title choosed by the sender.
         public String getTitle() {
              return title;
          * @return the recipient's email.
         public String getTo_email() {
              return to_email;
          * @return the recipient's name.
         public String getTo_name() {
              return to_name;
          * @param the background color choosed by the sender.
         public void setBgcolor(String string) {
              bgcolor = string;
          * @param the font choosed by the sender.
         public void setFont(String string) {
              font = string;
          * @param the sender's email.
         public void setFrom_email(String string) {
              from_email = string;
          * @param the sender's name.
         public void setFrom_name(String string) {
              from_name = string;
          * @param the card's id.
         public void setId(long i) {
              id = i;
          * @param the image choosed by the sender.
         public void setImage(String string) {
              image = string;
          * @param the message input by the sender.
         public void setMessage(String string) {
              message = string;
          * @param <code>true</code> if the card has been received, <code>false</code> otherwise.
          * If the application attempts to set the received field to true,
          * then the received field of the Card object is persisted to database
          * and an email is sent to the sender to notify them that the card has been received.
         public void setReceived(boolean b) {
              if (this.received == false && b == true) {
                   Mailer m = new Mailer();
                   try {
                        m.sendAcknowlegement(
                             to_email,
                             from_email,
                             from_name,
                             to_name,
                             id);
                        Connection con = DBConnection.getConnection();
                        PreparedStatement ps =
                             con.prepareStatement(Queries.setReceivedQuery);
                        ps.setLong(1, this.id);
                        ps.executeUpdate();
                        con.close();
                        this.received = true;
                   } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
          * @param <code>true</code> if the card has been sent, <code>false</code> otherwise.
          * If the application attempts to set the send field to true,
          * then the sent field of the Card object is persisted to database.
         public void setSent(boolean b) {
              if (this.sent == false && b == true) {
                   try {
                        Connection con = DBConnection.getConnection();
                        PreparedStatement ps =
                             con.prepareStatement(Queries.setSentQuery);
                        ps.setLong(1, this.id);
                        ps.executeUpdate();
                        con.close();
                   } catch (SQLException e) {
                        log.error("ERROR: impossible to update the sent field");
                        e.printStackTrace();
          * @param the title choosed by the sender.
         public void setTitle(String string) {
              title = string;
          * @param the recipient's email.
         public void setTo_email(String string) {
              to_email = string;
          * @param the recipient's name.
         public void setTo_name(String string) {
              to_name = string;
          * @return the send date.
         public String getSend_date() {
              return send_date;
          * @param the send date.
         public void setSend_date(String string) {
              send_date = string;
          * @return <code>true</code> if email has been sent, <code>false</code> otherwise.
         public boolean sendEmail() {
              try {
                   Mailer sm = new Mailer();
                   sm.sendCard(
                        this.from_email,
                        this.to_email,
                        this.from_name,
                        this.to_name,
                        this.id);
                   return true;
              } catch (Exception e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                   return false;
          * Retrieve the card from the database
         public static Card getCardFromId(int id) {
              Card c = new Card();
              c.id = id;
              try {
                   Connection con = DBConnection.getConnection();
                   PreparedStatement ps = con.prepareStatement(Queries.getCardFromID);
                   ps.setInt(1, id);
                   ResultSet rs = ps.executeQuery();
                   if (rs.next()) {
                        c.setBgcolor(rs.getString("db_bgcolor"));
                        c.setFont(rs.getString("db_font"));
                        c.setFrom_email(rs.getString("db_from_email"));
                        c.setTo_email(rs.getString("db_to_email"));
                        c.setFrom_name(rs.getString("db_from_name"));
                        c.setTo_name(rs.getString("db_to_name"));
                        c.setFont(rs.getString("db_font"));
                        c.setMessage((String) rs.getObject("db_message"));
                        c.setTitle(rs.getString("db_title"));
                        c.setSend_date(rs.getString("db_send_date"));
                        c.setImage(rs.getString("db_image"));
                        if (rs.getString("db_received").equals("y")) {
                             c.received = true;
                        } else if (rs.getString("db_received").equals("n")) {
                             c.setReceived(true);
                        if (rs.getString("db_sent").equals("y")) {
                             c.setSent(true);
                        } else if (rs.getString("db_sent").equals("n")) {
                             c.setSent(false);
                   System.out.println(c);
                   //con.close();
                   return c;
              } catch (SQLException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                   return null;
         public String toString() {
              return ("Title: " + this.title + ", " + "Id: " + this.id);
          * @param string
         public void setResponse(String string) {
              response = string;
         protected String saveCard() {
              try {
                   Connection con = DBConnection.getConnection();
                   PreparedStatement ps = con.prepareStatement(Queries.saveCard);
                   ps.setLong(1, (new java.util.Date()).getTime());
                   ps.setString(2, this.from_email);
                   ps.setString(3, this.to_email);
                   ps.setString(4, this.image);
                   ps.setString(5, this.bgcolor);
                   ps.setString(6, this.font);
                   ps.setString(7, this.from_name);
                   ps.setString(8, this.to_name);
                   ps.setString(9, this.message);
                   ps.setString(10, this.title);
                   ps.setString(11, this.send_date);
                   ps.executeUpdate();
                   con.close();
                   return "saved";
              } catch (SQLException e) {
                   log.error("ERROR: impossible to save the card");
                   e.printStackTrace();
                   return "notSaved";
         public Action getSaveCard() {
              return new Action() {
                   public String invoke() {
                        return saveCard();
    }The full source code for the project can be downloaded here:
    http://cours.java.free.fr/ecards-project/
    I would like to decouple the bean from the jdbc but I don't know how to. Can anyone help please?
    I found some sampes here http://access1.sun.com/codesamples/DataAccessObject.html
    but it does not have any update jdbc.
    Julien.

    Your DAO should have methods for getting and setting beans.
    For example:
    public Card getCard(long id){...}
    public void updateCard(Card c) {...}

  • How to start with Master data management

    Hi All,
    I want to start with Master Data Management. Can any one provide me proper material to get the knowledge on Master Data Management Integration. And What is the relationship between XI.and for starting MDM what all settings i have to do???
    Its really urget plz help me out.
    Thanks,
    Seema Khandelwal
    Message was edited by:
            Seema khandelwal

    Hi ..
    look at this documents
    /people/andreas.seifried/blog/2007/08/30/how-to-use-the-test-environment-of-the-mdm-enrichment-controller
    /people/harrison.holland5/blog/2006/11/27/mdm-syndication
    /people/harrison.holland5/blog/2007/01/22/testing-and-monitoring-an-interface-between-mdm-xi
    see this Wiki to find all the documentation on MDM:
    https://wiki.sdn.sap.com/wiki/display/HOME/MasterDataManagement
    Here, for the components you need to install:
    https://wiki.sdn.sap.com/wiki/display/HOME/MasterDataManagement+Components
    Others smart links are here:
    - sdn e-learning.
    https://www.sdn.sap.com/irj/sdn/mdm-elearning
    http://service.sap.com/installMDM for a
    you can use expression editor to do that:
    have a look at this guide on how dates can be calculated there
    with your field it can be very similar:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b025fab3-b3e9-2910-d999-a27b7a075a16
    for more details about expression editor:
    Calculation Fields chapter
    https://websmp108.sap-ag.de/~sapidb/011000358700006291622006E
    MDM 5.5 SP05 - ABAP API
    https://websmp101.sap-ag.de/~sapidb/011000358700000271902007E
    MDM 5.5 SP05 - ABAP API How To Guides (ZIP File)
    https://websmp101.sap-ag.de/~sapidb/011000358700000271912007E
    How to Identify Identical Master Data Records Using SAP MDM 5.5 ABAP APIs
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e060251e-b58d-2910-02a2-c9a1d60d9116

  • Hard disc repair needed. how to start with the snow leopard dvd?

    Hi,
    after a check with the apple hard disc program "festplattendienstprogramm" it found an error:
    something like "invalid amount of file hard links". It suggests to boot from the installation dvd.
    meanwhile I installed mac os lion, so I've got just the snow leopard dvd and tried to boot with holding down the C key before start up sound.
    But the system always boots from the hard disc. Maybe it's a problem with the apple bluetooth keyboard?
    holding down the c key didn't work (got the bt keyboard), and mac os lion is installed.
    Sincerely
    Sascha

    - the forum ate my post -
    Summarizing:
    Backup any data that you do not have a backup of. Disk repairs are not guaranteed. They can fail or be unrepairable requiring formatting the drive and a clean installation.
    Verify the smart status in disk utility. Highlight the drive. Read the status on the bottom of the window.
    Off the top of my head, I don't know that there is a free utility to read the number of errors and how close it.
    There is a utility called smartreporter that can help keep an eye on your hard drive.
    There is no guarantee the drive is about to fail or keep going for years; but it is suspect you have to start from the install disc to attempt a repair. Could be due to improper shut down.

  • Ergonomy of HU02 : how to start with the good tab ?

    hello,
    Is anyone know a way to start the HU02 with the tab "pack HU" just at the start ?
    Kind regards,
    Sébastien LAURENT

    Hi
    Aryav Pandey,
    Just want to do some additional explanation.
    This forum is discuss and ask questions about the C# programming language, IDE, libraries, samples, and tools.
    Actually, for question related to Asp.Net should be posted in Asp.Net forum.
    Here is the link http://forums.asp.net where you can contact Asp.Net experts.
    Best regards,
    Kristin
    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.

  • Data Access Object pattern (DAO)

    Sun's J2EE blueprints includes the DAO pattern:
    http://java.sun.com/blueprints/patterns/DAO.html
    I created some example DAO's:
    http://daoexamples.sourceforge.net
    http://daoexamples.sourceforge.net/xref/index.html
    Please send any feedback to sean /.at.\ seansullivan |.dot.| com

    Your example is beautiful, but what would be even more
    interesting to learn. How many lines of sql WOULD
    make StringBuffer the appropriate solution.It's not the number of lines, it's the number of Strings that will be appended at runtime. If all the Strings are literals, as in the OPs code, using StringBuffer will never be appropriate. It will always be slower than using +. That's a little misleading because + doesn't do anything at runtime when concatenating literals, the literals will be concatenated together at compile time. Usually SQL will contain a mixture of literals and non-literals. Generally, + will still be faster because it will be appending less Strings at runtime than StringBuffer, depending on the code.
    I suppose the question is how many Strings do you need to concatenate at runtime to make it worth while to use StringBuffer.
    Well, first of all, it's got to be more than two. The idea of using a StringBuffer is to avoid extra Object creation. If the + doesn't get compiled into StringBuffer appends, + between two Strings will create zero extras Objects; creating only the result String. The StringBuffer solution requires one extra Object; the StringBuffer. So in the case of concatenating only two Strings, the StringBuffer sotution is again inferior.
    When Concatenating three Strings you break even in the Object count. StringBuffer has an extra Object. 'Dumb' concatentation requires an extra Object.
    After three Strings. StringBuffer starts to come out ahead. But in reality, the difference is negligible. String concatenation is fast. I have to run tests 100s of thousands of times to get a clear difference in time. I find it unlikely that anyone will be concatenating enough Strings in a non-looping method to make it worth mucking up the code with StringBuffers. This is not a bottleneck.
    The time that it really counts is when you are concatenating inside loops. The compiler is not smart enough to optimize that type of code into an efficient StringBuffer solution. If you are concatenating to the same a String inside a loop, it is good practice to use a StringBuffer especially if the loop runs many times in a row or runs very often.
    The main point is for something like the OPs code, it doesn't really matter. Both versions will have essentially the same performance (very fast.) There is no reason to make the code less readable. I say, don't sacrifice readability just to make the code run more slowly. There are many ways to code less effecient without making it unreadable.

  • Data access Objects

    Deepak,
    Can you throw some light on the 'Data access Objects" pattern? and how it can be used with Entity beans? I am trying to apply this to the following scenario and having a hard time.
    We need users to be transparent of the data retrieval from various sources like oracle database, flat files or legacy storage. If I use the data access object pattern it is easier to use java classes in place of entity beans.
    Thanks
    Shreyas Kamat

    Shreyas,
    [For those not familiar with our Data Access Object Pattern, the
    beta version of the pattern is available on JDC (needs JDC login) at:
    http://developer.java.sun.com/developer/restricted/patterns/DataAccessObject.html]
    Data Access Objects (or DAOs) are objects that hide the database
    implementation from data clients. Data clients are any objects
    that need to retrieve data from the data source. And the data source
    could be anything that contains data, not necessarily only RDBMSs.
    For example, an external system could be a data source.
    Now using DAOs with Entity beans is applicable only in bean-managed
    persistence (BMP) scenario. In BMP, the entity beans are responsible
    to provide the data load and store implementation in the ejbLoad()
    and ejbStore() methods of the bean implementation. Without using
    the DAOs, the entity bean class will contain all the JDBC code (assuming
    that the data source is an RDBMS), SQL, etc. This makes the
    entity bean class bloated and difficult to manage when changes
    are made to the data logic. In addition, this tightly couples the
    data source implementation with the entity bean implementation.
    By using DAOs, the ejbStore() and ejbLoad() methods are much
    simpler. Also, it is easier to change from one datasource implementation
    to another by replacing the DAOs. Further flexibility is possible
    by employing the DAO factory strategy as described in the DAO pattern
    in our catalog.
    Coming back to you point about making the data access transparent
    to the clients; it is possible to achieve this by using DAO and
    DAO factory strategy. In the current version of the pattern,
    included in the book, we provide sample code to show how
    to design DAO classes and to apply DAO factory strategy.
    On your last point about using java classes instead of entity beans, this
    is not the intention of the DAO pattern. Entity beans serve a different
    purpose in the architecture as coarse-grained transactional components.
    entity beans use DAOs in BMP implementations, but are not replaced
    by DAOs. However, DAO classes are reusable. The same DAO that is
    used by an entity bean to retrieve some data in one application scenario,
    can be reused by a servlet in another application scenario
    that needs the same data, but does not use entity beans.
    So bottom line is that DAOs address the need to data access and
    manipulation and work together with entity beans in BMP implementations.
    thanks,
    -deepak

  • Data Access Objects and associations....

    Ive got a few classes which are 'value based', and represent some configuration for some dynamic part of my application.
    I was going to employ the Data Access Objects pattern (http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html) to decouple the data source (either XML or RDB in this case) from the content.
    In my case though, I have associations between the content.
    E.g, an X contains 0..n Ys' which have 0..1 Zs'.
    So, X has 'getYs()' for example.
    Is the DAO pattern meant for cases like this, or just for single data object cases (E.g, 'Customer') with simple properties?
    I cant see any disadvantages for using it in my case, but wondered if any one has any thoughts on the design?

    The aim of the DAO is to hide the implementation of the datasource to the clients (i.e the classes using it). And the reason is the client should not care how the data is stored. It also means that I can change the way I store my data without changing the client(s) code (the client calls interface methods that do not change).
    If your code satisfies the above, it is implementing DAO, and it should not and does not matter how many Y's are in your X's or Z's...
    Always make a distinction between the general aim of a Design Pattern (its essence) and the (usually simple, even simplistic) examples supplied by different authors to illustrate the pattern.

  • Data Access Object for Data Warehouse?

    Hi,
    Does anyone know how the DAO pattern looks like when it is used for a data warehouse rather than a normal transactional database?
    Normally we have something like CustomerDAO or ProductDAO in the DAO pattern, but for data warehouse applications, JOINs are used and multiple tables are queried, for example, a query may contains data from the Customer, Product and Time table, what should the DAO class be named? CustomerProductTimeDAO?? Any difference in other parts of the pattern?
    Thanks in advance.
    SK

    In my opinion, there are no differences in the Data Access Object design pattern which have any thing to do with any characteristic of its implementation or the storage format of the data the pattern is designed to function with.
    The core pupose of the DAO design pattern is to encapsulate data access code and separate it from the business logic code of the application. A DAO implementation might vary from application to application. The design pattern does not specify any implementation details. A DAO implementation can be applied to group of XML data files, an Excel-based CSV file, a relational database, or an OS file system. The design is the same for all these, it is the implementation that varies.
    The core difference between an operational database and a strategic data warehouse is the purpose of why and how the data is used. It is not so much a technical difference. The relational design may vary however, there may be more tables amd ternary relationships in a data warehouse to support more fine-tuned queries; there may be less tables in a operational database to support insert/add efficiencies.
    The DAO implementation for a data warehouse would be based on the model of the databases. However the tables are set up, that is how the DAO is coded.

  • Managed Beans and Data Access Object

    I have a question / need help understanding how to configure backing bean and model objects so that memory and object creation/deletion is done as efficiently as possible.
    1. I have a .jsf page with a form and a commandbutton that submits the form inputs to a backing bean (enrollispbean is backing bean)
    <h:commandButton value="Enter" action="#{enrollispbean.insert}"/>
    2. The backing bean is used for form handling - the insert() method is used to read the data fields from the form and create a SQL string that will be submitted to a model object, DbInsert, that is used as a generic data access object that connects to the database and insert the SQL string:
    public class EnrollIspBean {
    private String beanvar1="";
    private String beanvar2= "";
    // DbInsert is data access object
    private DbInsert dbinsert = new DbInsert();
    public String insert (){
    String sqlstmt;
    sqlstmt = "INSERT INTO ispmain VALUES(beanvar1, beanvar2,..)"
    dbinsert.insert(sqlstmt);
    return "success"; }
    3. DbInsert is the data access object that contains a method, insert(), that accepts a sql string to insert into the database. This method contains the code to obtain a connection from the database connection pool and then execute the sql statement (note: error checking code not shown):
    public class DbInsert {
    public void insert(String sqlstmt) throws SQLException {
    Connection conn = null;
    GetDBConnection getdbconnection = new GetDBConnection();
    PreparedStatement stmt = null;
    conn = getdbconnection.getdbconn();
    stmt = conn.prepareStatement(sqlstmt);
    stmt.executeUpdate();
    stmt.close();
    conn.close();
    return;
    Where I need help understanding is how to set up the scope for the managed beans and data access object. Currently, I have the backing bean within the session scope (using the facesconfig.xml file). My main question is how to set up the scope for the Data Access Object - currently I do not have it as a managed bean within facesconfig.xml. Instead I am creating a new instance within the backing bean:
    private DbInsert dbinsert = new DbInsert();
    Is this the best way to do this? Will the DBInsert object now be tied to the session scope of the backing bean (i.e., when backing bean is deleted, the DbInsert object will be deleted from session scope as well.)
    Ideally I would like the data access object to be available as a shared object throughout the life of the application. When I was programming using a servlet approach, I would have created a servlet to load on startup. Now that I'm using java server faces, I'm confused about the scope / how to efficiently set up a data access object that I want to be available to all backing beans in the application.
    tnanks for any help understanding this.
    Tom

    I was thinking about setting the data access object as application scope so that it can be used by an backing bean to execute sql statements.
    If I do set it as application scope, however, if I do this, do I still need to declare a new instance of the object from within each bean that uses the object?
    For example do I need to declare a new instance of the data access object from within the bean? or, should I assume that there is always an instance of the bean available in the application scope, and if so, how do I reference it from within the bean?
    Bean Code:
    public class EnrollIspBean {
    // DbInsert is data access object
    private DbInsert dbinsert = new DbInsert();
    Finally, I understand performance may be an issue if I have one instance of the data access object available in the application scope - is there a way to make multiple instances available in the application scope?
    thanks

  • I recently got the iPhone 4s, but my iPod has a lot of apps with a lot of data on them and don't want to start over. I already synced my iPhone from the computer that had all my apps from my iPod, how do i transfer the data over, the other apps did.

    I recently got the iPhone 4s, but my iPod has a lot of apps with a lot of data on them and don't want to start over. I already synced my iPhone from the computer that had all my apps from my iPod, how do i transfer the data over, the other apps did. But some reason the app Clash Of Clans did not. Thank you.

    If I wiped my phone I wouldn't have the contacts on my phone to send to my self.    I would need to take just the contacts from my back up. I would have to do this through iTunes and I don't see how I can just extract the contacts only from my back up. From what I can figure out it is all or nothing

  • Dynamically built query on execution How to save the data in Object Type

    Hi,
    In pl/sql I am building and executing a query dynamically. How can I stored the output of the query in object type. I have defined the following object type and need to store the
    output of the query in it. Here is the Object Type I have
    CREATE OR REPLACE TYPE DEMO.FIRST_RECORDTYPE AS OBJECT(
    pkid NUMBER,
    pkname VARCHAR2(100);
    pkcity VARCHAR2(100);
    pkcounty VARCHAR2(100)
    CREATE OR REPLACE TYPE DEMO.FIRST_RECORDTYPETAB AS TABLE OF FIRST_RECORDTYPE;Here is the query generated at runtime and is inside a LOOP
    --I initialize my Object Type*
    data := new FIRST_RECORDTYPETAB();
    FOR some_cursor IN c_get_ids (username)
    LOOP
    x_context_count := x_context_count + 1;
    -- here I build the query dynamically and the same query generated is
    sql_query := 'SELECT pkid as pid ,pkname as pname,pkcity as pcity, pkcounty as pcounty FROM cities WHERE passed = <this value changes on every iteration of the cursor>'
    -- and now I need to execute the above query but need to store the output
    EXECUTE IMMEDIATE sql_query
    INTO *<I need to save the out put in the Type I defined>*
    END LOOP;
    How can I save the output of the dynamically built query in the Object Type. As I am looping so the type can have several records.
    Any help is appreciated.
    Thanks

    hai ,
    solution for Dynamically built query on execution How to save the data in Object Type.
    Step 1:(Object creation)
    SQL> ED
    Wrote file afiedt.buf
    1 Create Or Replace Type contract_details As Object(
    2 contract_number Varchar2(15),
    3 contrcat_branch Varchar2(15)
    4* );
    SQL> /
    Type created.
    Step 2:(table creation with object)
    SQL> Create Table contract_dtls(Id Number,contract contract_details)
    2 /
    Table created.
    Step 3:(execution Of procedure to insert the dynamic ouput into object types):
    Declare
    LV_V_SQL_QUERY Varchar2(4000);
    LV_N_CURSOR Integer;
    LV_N_EXECUTE_CURSOR Integer;
    LV_V_CONTRACT_BR Varchar2(15) := 'TNW'; -- change the branch name by making this as input parameter for a procedure or function
    OV_V_CONTRACT_NUMBER Varchar2(15);
    LV_V_CONTRACT_BRANCH Varchar2(15);
    Begin
    LV_V_SQL_QUERY := 'SELECT CONTRACT_NUMBER,CONTRACT_BRANCH FROM CC_CONTRACT_MASTER WHERE CONTRACT_BRANCH = '''||LV_V_CONTRACT_BR||'''';
    LV_N_CURSOR := Dbms_Sql.open_Cursor;
    Dbms_Sql.parse(LV_N_CURSOR,LV_V_SQL_QUERY,2);
    Dbms_Sql.define_Column(LV_N_CURSOR,1,OV_V_CONTRACT_NUMBER,15);
    Dbms_Sql.define_Column(LV_N_CURSOR,2,LV_V_CONTRACT_BRANCH,15);
    LV_N_EXECUTE_CURSOR := Dbms_Sql.Execute(LV_N_CURSOR);
    Loop
    Exit When Dbms_Sql.fetch_Rows (LV_N_CURSOR)= 0;
    Dbms_Sql.column_Value(LV_N_CURSOR,1,OV_V_CONTRACT_NUMBER);
    Dbms_Sql.column_Value(LV_N_CURSOR,2,LV_V_CONTRACT_BRANCH);
    Dbms_Output.put_Line('CONTRACT_BRANCH--'||LV_V_CONTRACT_BRANCH);
    Dbms_Output.put_Line('CONTRACT_NUMBER--'||OV_V_CONTRACT_NUMBER);
    INSERT INTO contract_dtls VALUES(1,CONTRACT_DETAILS(OV_V_CONTRACT_NUMBER,LV_V_CONTRACT_BRANCH));
    End Loop;
    Dbms_Sql.close_Cursor (LV_N_CURSOR);
    COMMIT;
    Exception
    When Others Then
    Dbms_Output.put_Line('SQLERRM--'||Sqlerrm);
    Dbms_Output.put_Line('SQLERRM--'||Sqlcode);
    End;
    step 4:check the values are inseted in the object included table
    SELECT * FROM contract_dtls;
    Regards
    C.karukkuvel

  • Facing lot of problems with the DATA object  -- Urgent

    Hi,
    I am facing lot of problems with the data object in VC.
    1. I created the RFC initially and then imported the data object in to VC. Later i did some modifications to RFC Function module,and when i reload the data object, I am not able to see the new changes done to RFC in VC.
    2. Even if i delete the function module, after redeploying the IVIew, results are getting displayed.
    3. How stable is the VC?
      I restarted the sql server and portal connection to R3 is also made afresh.... still i am viewing such surprise results..
    please let me know what might be the problem.

    Hi Lior,
    Are u aware of this problem.
    If yes, please let me know...
    Thanks,
    Manjunatha.T.S

  • How to find the date when object is moved from quality to production server

    Hi Experts,
    I am working with BADI ZMM_PUR_REQ_PROC_001-Method Check and BADI ZME_PROCESS_PO_CUST-Method Check.
    I need to add a check that a particular logic should be implemented only after this object is moved to the production server.
    How can i check the date when an object (in my case this BADI) is moved to the production server?
    <Removed by moderator>
    Thanks in advance.
    Edited by: Vinod Kumar on Aug 1, 2011 10:55 AM

    Hi Sakshi,
    So your reqt is that the documents created after your Transport implementation date should pass the check and others (old ones) should ignore.
    I will recommend, if at all possible, to make all the old documents compatible to your check by doing a separate initial loading /one time activity to avoid this kind of hardcoding.
    IF not at all possible to do so, then I think you should better hardcode your Transport req number and fetch date (AS4DATE) from E070 table and only if any entry exists, use that date as your required date. I believe this will be the date of transport imported in the target system.
    You can avoid hardcoding Transport number by picking latest transport with respect to your object (BADI) using E071 table, but that will go wrong once you send any future changes in this BADI to Prod, so better to hardcode the transport.
    BR,
    Diwakar

Maybe you are looking for