Populating fields from database values

I have a page being populated from database values. I used the Application Builder Wizard to create the application. One of the fields is displaying on the report, but when I click edit, the value is not there. The field is defined as a float and being displayed as a text item. I have created this Application twice with the same results.
Any ideas?
thanks!
Christie

Thank you for the quick reply!
I turned on the debug, to ensure the automatic fetch
process it on and it is. The edit page has 7
fields, all are being populated except for this one.
I have confirmed it is using the correct database
column and it is replacing the existing value the
same as the other fields.
Any other ideas to what could be going on?You can see each page item assignment in the debug output. Look there to see where the page item is being set, and potentially unset I suppose. The thing to look for here might be page processes that might be interacting with that item.
You could also simply drop the problematic page item and recreate it to see if you can make the value stick.
Earl

Similar Messages

  • APEX4: Populating fields from database based on the SelectList value

    Hi,
    I've a Select List and 4 Text Fields on a form. On selecting a value on the Select List, I've to populate the Text Fields by fetching its values from the database by using the Select List value as the primary key.
    How can I do this in APEX 4?
    Thanks for the help.
    --Hozy                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Thank you so much for helping me out.
    Yes, it comes from the same table account.
    These are the sqls to fetch the 4 values in each dynamic action:
    select a.address1 from account a where a.account_id = :P14_ACCOUNT
    select a.address2 from account a where account_id = :P14_ACCOUNT
    select a.city from account a where a.account_id = :P14_ACCOUNT
    select a.postal_code from account a where a.account_id = :P14_ACCOUNT
    Right now, I only have one dynamic action for text field P14_BILLING_ADDRESS_1, and even for just one the value is not showing up in it. Please note that when I added for dynamic actions, the the values were showing up in all the 4 text fields before.
    Then when I added 4 more dynamic actions for a different Select List (P14_CUSTOMER), but for the same text fields, it all stopped working. And now even a single dynamic action is not working. This is how the sql for next 4 dynamic actions looked like:
    select c.address1 from customer c where c.customer_id = :P14_CUSTOMER
    select c.address2 from customer c where c.customer_id = :P14_CUSTOMER
    select c.city from customer c where c.customer_id= :P14_CUSTOMER
    select c.postal_code from customer c where c.customer_id= :P14_CUSTOMER
    }

  • Populating Fields from Database

    Hi everyone,
    Need some help from the experts.  I have a PDF form that is already connected to a Progress/OpenEdge database through ODBC connection.  Here's what I want to happen:
    Just as an example, in the database suppose the 'Job' table contained 3 fields: JobID, JobDescription, and CustomerName.  When a user enters a job number into a specific PDF form field which corresponds to the JobID field of the database, the form fields in the PDF for Job Description and Customer Name auto-populate with the corresponding information from the database.
    Can this be done?
    Thanks so much,
    Jon

    Thank you for the quick reply!
    I turned on the debug, to ensure the automatic fetch
    process it on and it is. The edit page has 7
    fields, all are being populated except for this one.
    I have confirmed it is using the correct database
    column and it is replacing the existing value the
    same as the other fields.
    Any other ideas to what could be going on?You can see each page item assignment in the debug output. Look there to see where the page item is being set, and potentially unset I suppose. The thing to look for here might be page processes that might be interacting with that item.
    You could also simply drop the problematic page item and recreate it to see if you can make the value stick.
    Earl

  • How to populate a field from database through personalization

    I need to populate value of a field from database on self service transaction web page. This field is not configured as EIT or SIT, nor available in seeded transaction.I need to know abt creating some item through personalization where i can write a query . This item will execute the query and display the returned value on the page or something on the similar line.
    Thanks in advance,
    Tanveer

    This workaround should be used as a one time approach till you move to 11.5.10 CU3.
    Here are the details,
    You just need to add the following tags inside the site or function level customization document, remember it should be either site or function only no other levels are supported for adding a new item.
    before adding the following tags you need to find out the following details,
    1. what is the last item in the advancedTable, column or columnGroup in the base metadata. Do not conside the columns inside the columnGroups for this, just the last item which might be a column or a columngroup. Get the if of that item.
    2. You should know what is the view instance and viewattribute you will be attaching
    3. Remember you can only add columns through personalization and not columnGroups.
    4. Replace the appropriate values for the properties amrked with {...} with your own values. You can change the other properties to reflect any specific requirement you want. Make sure you provide correct values.
    <insert after="{the id you got from step 1}">
    <oa:column id="{yourid}" adminCustomizable="true" bandingShade="none"
    cellNoWrapFormat="false" columnDataFormat="textFormat" displayGrid="true"
    rendered="true" scope="." totalValue="false" userCustomizable="false"
    xmlns:oa="http://xmlns.oracle.com/oa">
    <ui:columnHeader xmlns:ui="http://xmlns.oracle.com/uix/ui">
    <oa:sortableHeader id="{yourid}" adminCustomizable="true"
    cellNoWrapFormat="false" initSortSeq="none" prompt="{your prompt}"
    rendered="true" required="no" scope="." sortState="no"
    userCustomizable="false"/>
    </ui:columnHeader>
    <ui:contents xmlns:ui="http://xmlns.oracle.com/uix/ui">
    <oa:messageStyledText id="{yourid}" adminCustomizable="true"
    cellNoWrapFormat="false" dataType="VARCHAR2" initSortSeq="none" queryable="false" rendered="true" required="no" scope="."
    selectiveSearchCriteria="false"
    serverUnvalidated="false" sortState="no" tipType="none" totalValue="false"
    userCustomizable="false" vAlign="middle" viewAttr="{your view attribute}" viewName="{your view instance name}"
    warnAboutChanges="true"/>
    </ui:contents>
    </oa:column>
    </insert>
    You can insert these tags at the end of any existing tags within the <modifications>
    </modifications> tag in the document.

  • Missing class indicator field from database row

    Hi,
    I have following problem :
    There is a class inheritance with root interface and 4 subclasses, they are initialized with class indicator field. If I use ReadAllQuery with an interface or some of concrete class as search class - it is working perfect, but if I try to build query with custom selected fields (addPartialAttribute) I always get an error - Missing class indicator field from database row.
    AFAIK This field have not to be mapped in Workbench to real table column, how can I tell TopLink that I will read this indicator field too by reading some custom fields ? I thought TopLink reads such fields automatically, like it does it with primary keys.
    Thank you
    Maksim

    This sounds like an issue with our partial attribute queries and inheritance as the type indicator column must always be read. Can you map the type indicator to a read-only attribute (mark mapping as read-only) and include this in your list of attributes as a work-around?
    Doug

  • Want JTree e.g. of populating data from database.

    I want ur JTree example of populating data from database, can u plz give me that eg.?
    Awaiting 4 ur reply.

    Hi,
    AFAIK, there is no direct approach to populate a JTree directly from a resultset. However, JTree can use a DOM tree as its model by using the adapter pattern. The procedure to do this is well-documented in the SUN website and the link is provided below. The code to convert a resultset to XML is provided below:
    protected void resultSetToXML(OutputStream out,
    ResultSet rs,
    String stylesheet)
    throws IOException, ServletException {
    // Create reader and source objects
    SqlXMLReader sxreader = new SqlXMLReader();
    SqlInputSource sis = new SqlInputSource(rs);
    // Create SAX source and StreamResult for transform
    SAXSource source = new SAXSource(sxreader, sis);
    StreamResult result = new StreamResult(out);
    // Perform XSLT transform to get results. If "stylesheet"
    // is NULL, then use identity transform. Otherwise, parse
    // stylesheet and build transformer for it.
    try {
    // Create XSLT transformer
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t;
    if (stylesheet == null) {
    t = tf.newTransformer();
    } else {
    // Read XSL stylesheet from app archive and wrap it as
    // a StreamSource. Then use it to construct a transformer.
    InputStream xslstream = _config.getServletContext().
    getResourceAsStream(stylesheet);
    StreamSource xslsource = new StreamSource(xslstream);
    t = tf.newTransformer(xslsource);
    // Do transform
    t.transform(source, result);
    } catch (TransformerException tx) {
    throw new ServletException(tx);
    The classes SQLXMLReader and other classes used in this example are available in the following java packages.
    import java.sql.*;
    import javax.sql.DataSource;
    import javax.xml.parsers.*;
    import javax.xml.transform.*;
    import javax.xml.transform.sax.*;
    import javax.xml.transform.stream.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.AttributesImpl;
    The following is the link that explains how to load a JTree from DOM.
    http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPDOM6.html
    Cheers,
    vidyut

  • Populating Multirecord text fields from Tlists value's combinations

    I have a UI wherein there are two T lists, one on the Left and other on the Right. The left one contains
    From values and the Right one contains To values. There's one Button which when Pressed should populate
    a Data Block which has multi record text fields just below the button with all the possible combinations of
    the T lists elements. The Text fields have the values From, To, Time, Unit. When populated From and Two will
    get the values from the combinations and the user will enter the values in other fields i.e. Time and Unit,
    Then the user can save the Records.
    e.g. If the Left T list contains Red, Blue and the Right T List contains Green, Black. Then on pressing
    the button below the T lists, the text fields From and Two of a data block displayed in the same window
    should get populated with all the possible combinations as:
    From || To || Unit || Time
    Red Green
    Red Black
    Blue Green
    Blue Black
    Now the user can enter the values for Unit as well as Time and when he does save the Records should be inserted
    for the Data Blocks DML Source that's some table.
    What I'm trying is:
    On pressing the Button i'm writing code that will have Two PL/SQL Tables(Index by binary_integer). One will have
    all the values of the left T List and the other with all the values of right T List.
    I do it as in the WHEN BUTTON PRESSED as:
    DECLARE
    TYPE varchar_table IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
    from varchar_table;
    to varchar_table;
    v_count1 NUMBER;
    v_count2 NUMBER;
    v_count3 NUMBER;
    v_count4 NUMBER;
    BEGIN
    v_count1 := Get_List_Element_Count('CONTROL.FROM_TYPE');
         FOR i IN 1..v_count1 LOOP
              from(i) := Get_List_Element_Value('CONTROL.FROM_TYPE', i);
         END LOOP;
    v_count2 := Get_List_Element_Count('CONTROL.TO_TYPE');
         FOR i IN 1..v_count2 LOOP
              to(i) := Get_List_Element_Value('CONTROL.TO_TYPE', i);
         END LOOP;
    END;
    Now how will I populate the text fields with the values in the tables that i got with the piece of code above.
    Any help would be appreciated. Any other method other than the one i'm trying is also welcome. Please note that
    i'm not using any table to store the elements in the T Lists. The lists get values at runtime by
    user's selection.
    Thanks,
    Abhishek.

    Try and stay civil in your postings. The solotion should be to simply issue a GO_BLOCK, followed by a CREATE_RECORD followed by setting the approriate values :block.value = <value from list>

  • CRVS2010 beta - Date field from database does not display in report

    Hi there - can someone please help?!
    I am getting a problem where a date field from the database does not display in the report viewer (It displays on my dev machine, but not on the client machines...details given below)
    I upgraded to VS 2010
    I am using the CRVS2010 Beta
    My development machine is Windows 7 - and so is my fellow developer's
    We are using Microsoft SQL Server 2000
    We run the queries within VS and then we send the data table to VS using .SetDataSource
    We have a few reports which display the date on our dev machines (whether we run the EXE or from within Visual Studio)
    When we roll out to the client machines (running Windows XP SP3) then everything works, except that the date does not display (on quite a few reports)
    This is the only real issue I have had - a show stopper for me
    The rest works well - any input will be greatly appreciated
    Regards,
    Ridwan

    Hi Ridwan,
    After much testing I have it all working now using CRDB_adoplus.dll as a data source ( XML )
    Alter your Config file to look like this:
    <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
    </startup>
    Then using the code below, and CR requires the Schema to be able to read the date format.
    private void SetToXML_Click(object sender, EventArgs e)
    CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
    ISCDReportClientDocument rcd;
    rcd = rptClientDoc;
    string connString = "Provider=SQLOLEDB;Data Source=dwcb12003;Database=xtreme;User ID=sb;Password=password";
    string sqlString = "Select * From Orders";
    OleDbConnection oleConn = new OleDbConnection(connString);
    OleDbDataAdapter oleAdapter = new OleDbDataAdapter(sqlString, oleConn);
    //OleDbDataAdapter oleAdapter2 = new OleDbDataAdapter(sqlString2, oleConn);
    DataTable dt1 = new DataTable("Orders");
    oleAdapter.Fill(dt1);
    System.Data.DataSet ds = new System.Data.DataSet();
    // We need the schema to get the data formats
    ds.WriteXml("c:
    sc.xml", XmlWriteMode.WriteSchema);
    //Create a new Database Table to replace the reports current table.
    CrystalDecisions.ReportAppServer.DataDefModel.Table boTable = new CrystalDecisions.ReportAppServer.DataDefModel.Table();
    //boMainPropertyBag: These hold the attributes of the tables ConnectionInfo object
    PropertyBag boMainPropertyBag = new PropertyBag();
    //boInnerPropertyBag: These hold the attributes for the QE_LogonProperties
    //In the main property bag (boMainPropertyBag)
    PropertyBag boInnerPropertyBag = new PropertyBag();
    //Set the attributes for the boInnerPropertyBag
    boInnerPropertyBag.Add("File Path ", @"C:\sc.xml");
    boInnerPropertyBag.Add("Internal Connection ID", "{680eee31-a16e-4f48-8efa-8765193dccdd}");
    //Set the attributes for the boMainPropertyBag
    boMainPropertyBag.Add("Database DLL", "crdb_adoplus.dll");
    boMainPropertyBag.Add("QE_DatabaseName", "");
    boMainPropertyBag.Add("QE_DatabaseType", "");
    //Add the QE_LogonProperties we set in the boInnerPropertyBag Object
    boMainPropertyBag.Add("QE_LogonProperties", boInnerPropertyBag);
    boMainPropertyBag.Add("QE_ServerDescription", "NewDataSet");
    boMainPropertyBag.Add("QE_SQLDB", "False");
    boMainPropertyBag.Add("SSO Enabled", "False");
    //Create a new ConnectionInfo object
    CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo boConnectionInfo =
    new CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo();
    //Pass the database properties to a connection info object
    boConnectionInfo.Attributes = boMainPropertyBag;
    //Set the connection kind
    boConnectionInfo.Kind = CrConnectionInfoKindEnum.crConnectionInfoKindCRQE;
    //*EDIT* Set the User Name and Password if required.
    boConnectionInfo.UserName = "";
    boConnectionInfo.Password = "";
    //Pass the connection information to the table
    boTable.ConnectionInfo = boConnectionInfo;
    //Get the Database Tables Collection for your report
    CrystalDecisions.ReportAppServer.DataDefModel.Tables boTables;
    boTables = rptClientDoc.DatabaseController.Database.Tables;
    //For each table in the report:
    // - Set the Table Name properties.
    // - Set the table location in the report to use the new modified table
    boTable.Name = "Orders";
    boTable.QualifiedName = "Orders";
    boTable.Alias = "Orders";
    rptClientDoc.DatabaseController.SetTableLocation(boTables[0], boTable);
    //Verify the database after adding substituting the new table.
    //To ensure that the table updates properly when adding Command tables or Stored Procedures.
    rptClientDoc.VerifyDatabase();
    MessageBox.Show("Data Source Set", "RAS", MessageBoxButtons.OK, MessageBoxIcon.Information);
    Thanks again
    Don

  • Urgent......  how to select few fields, from database table, (dynamic ita.)

    Dear all experts,
    I am able to populate all fields data from database table, using dynamic table creation.
    eg,
    SELECT *    FROM (w_tabname)    INTO    TABLE <t_itab>.
    where w_tabname is the table name given by the user, and t_itab is field symbol.
    but some requirement is like that i need to pick up only few fields, <b>which user will give at the runtime.</b>
    <b>I can</b> take those fields from file into any internal table,
    but the problem is that instead of <b>select *</b>, i need to put selected the fields given by user.
    i have tried with field symbol, it is not working (as per my knowledge.)
    do i need to create any structures dynamically ?
    Can anybody please help in this regards ?
    Your help will be surely rewarded with points.
    Waiting for reply..
    Regards
    Vinay

    Hi Vinay ,
    Adding to the below code , you can use some more fields in the select stmt as below:-
    REPORT ychatest.
    PARAMETERS : p_field1 LIKE dd03l-fieldname,
                             P_field2 LIKE dd03l-fieldname,
                             p_table LIKE dd03l-tabname.
    FIELD-SYMBOLS : <fs> TYPE STANDARD TABLE.
    SELECT (p_field1) (p_field2) ( FROM (p_table) INTO TABLE <fs>.
    Now p_field1 & p_field2  belong to the same table since you have give the user to enter only one table name.
    This should work fine.
    please try & let me know .
    Thanks & Regards,
    Daniel

  • Very very urgent. population data from database into dropdownbox

    Hi,
    i imported a model through ejbs
    this is to create new entries into database ,
    and my scenerio iso now i need to populate the values that i stored into database thro EJBS in a drop down box of wd application.
    plz help me through code ,i am new to java webdynpro...
    neede very urgently,
    Thanx .
    Arjun.G
    Message was edited by:
            arjun swamy

    Hi,
    Have a look at these threads
    Dropdown by index in table - fetching values from database
    Dropdown by index
    Kind Regards,
    Saravanan K

  • Creating dynamically JTree from database values

    Hi,
    I have a local database with some node values. I receive these values from database as a String[].
    short example:
    String[] Values = {"mainNode","Processors","mainNode","RAM","mainNode","Monitors",
    "Processors","INTEL","Processors","AMD","RAM","Kingston","RAM","GoodRAM",
    "Kingston","400MHz","Kingston","433MHz"}First value is higher node, second is a child.
    I'd like to produce dynamically JTree from Values[] like below:
    MainNode
    |----Processors
          |----INTEL
          |----AMD
    |----RAM
          |----Kingston
                |----400MHz
                |----433MHz
          |----GoodRam
    |----MonitorsI can't build up any working and fast solution :(
    Can anyone help me ?
    Please for any advices (samples) which will help me to apply it.
    Dearly regards!

    This is a relatively straight forward task but it smacks of being homework so unless you post what you have already done you are unlikely to be given any code.
    As a hint -
    Go through the data creating a Map between the parent value and a child DefaultMutableTreeNode which contains as user object the child String.
    When you extract a parent String from the data lookup the parent DefaultMutableTreeNode in the map and add the child DefaultMutableTreeNode to the parent DefaultMutableTreeNode.
    Note - All the map is doing is giving you a quick way of looking up a DefaultMutableTreeNode given a parent name.
    Note - that your tree will have problems if the same value appears in two or more branches!

  • Populating JTree from database

    Hi experts,
    I need some feedbacks about the way i populate my JTree from database, Is there any better alternatives?
    If yes, try explain it in detail.. I'm still new in Java.
    Sample database table:
    |       node_id      |       name      |       parent       |       hasChild      |
    |         1          |     garbage     |        null        |           1         |
    |         2          |       item      |          1         |           1         |
    |         3          |      mouse      |          2         |           0         |
    |         4          |       board     |          2         |           0         |
    |         5          |       item2     |          1         |           1         |
    |         6          |       item3     |          1         |           1         |
    |         7          |       pants     |          5         |           0         |
    -----------------------------------------------------------------------------------Here's the sample of my code:
    //... ResultSet rs = .....
    rs.last();
    int rowCount = rs.getRow(); //Get the total number of row in database table
    rs.beforeFirst();
    int i = 0;
    int j = 0;
    String [] nodeID = new String[rowCount];  //The node ID
    String [] parentID = new String[rowCount];  //A pointer to its parent ID
    DefaultMutableTreeNode [] node = new DefaultMutableTreeNode[rowCount]; //The node
    while(rs.next()) {
         String name = rs.getString("name");
         Boolean bool = rs.getBoolean("hasChild");
         node[i] = new DefaultMutableTreeNode(name,bool);
         parentID[i] = rs.getString("parent");
         nodeID[i] = rs.getInt("node_id") + "";
            //Set as root node when the pointer is null               
         if(parentID.equals("null")) {
              rootNode = node[i];
         i++;
    for(i=0; i<rowCount; i++) {
         for(j=0; j<rowCount; j++) {
              if(parentID[j].equals(nodeID[i]) && node[i] != null) {
                   node[i].add(node[j]);
    node[i] = null; //Obligates the parent after finish adding the child (to prevent unnecessary loops)
    //... tree = new JTree(rootNode);
    Thanks for the trouble,
    Regards,
    David

    The execution time are base on the code i post'ed here.
    Average over 30times using Vector = 640048 nanosecond to execute.
    Vector<String> nodeID = new Vector<String>();
    Vector<DefaultMutableTreeNode> node = new Vector<DefaultMutableTreeNode>();
    Vector<String> parentID = new Vector<String>();
    rs.last();
    int rowCount = rs.getRow();
    rs.beforeFirst();
    k=0;
    while(rs.next()) {
         String name = rs.getString("name");
         Boolean hasChild = rs.getBoolean("hasChild");
         node.addElement(new DefaultMutableTreeNode(name,hasChild));
         nodeID.addElement(rs.getInt("node_id")+"");
         parentID.addElement(rs.getString("parent"));
         if(parentID.elementAt(k).equals("null")) {
              rootNode = node.elementAt(k);
         k++;
    i=0;
    while(i<rowCount) {
         j=0;
         while(j<rowCount) {
              if(parentID.elementAt(j).equals(nodeID.elementAt(i)) && node.elementAt(j) != null) {
                   node.elementAt(i).add(node.elementAt(j));
                   if(!node.elementAt(i).getAllowsChildren())
                        node.insertElementAt(null,j);
              j++;
         i++;
    }Average over 30times using LinkedList = 95623 nanosecond to execute.
    //This section will have a class Nodes
    LinkedList<Nodes> gather = new LinkedList<Nodes>();
    while(rs.next()) {
         node = new DefaultMutableTreeNode(rs.getString("name"),rs.getBoolean("hasChild"));                    
         gather.add(new Nodes(rs.getInt("node_id") + "",node,rs.getString("parent")));
    for(Nodes findParent : gather) {                    
         if(findParent.getParentID().equals("null")) {
              findParent.setRoot(findParent.getNode());
              rootNode = findParent.getRoot();
         for(Nodes findChild : gather){
              if(findChild.getParentID().equals(findParent.getNodeID()))
                   findParent.getNode().add(findChild.getNode());               
    }As for the Array method i used from the previous post, the Average code execution time is x3 larger than the vector i used. So please do not use that method.
    Note: 1. The code i post can be improved further. 2. Execution time is based on individual computer.
    Well, I think i'll stop here. Anyone who wanted to know which method is more efficient currently, here's the answer.
    Hope that it helps anyone who have the problem here =).
    Edited by: DavidTW on May 23, 2011 3:14 PM
    Improved Version : Using for-each loop ( Effective Java, Second Edition, Joshua Bloch, Pg. 210).

  • Autofill form text fields from database

    I have made a form in asp code with text fields. Behind this page is a database (access).
    This database contains static information and does not need to be updated. It is only for output.
    In this form, there are some text fields to be filled in.
    Reference
    First name
    Last name
    E-mail address
    Telephone number
    This information is in the database.
    What I try to do is that when the first text field "Reference" is filled, the related information is selected from the database and automatically put in the other corresponding text fields.
    Anybody any idea how to do this?

    I don't use ASP, but the simple way to approach this problem is to have two pages. The first page contains a form with a text field for Reference and a submit button. Set the form's method to GET, and the action to the page that contains the full form.
    In the page that contains the full form, create a recordset to select the details from the database, using the URL parameter for Reference as a filter. You can then bind the results from the recordset to the value attributes of the remaining form fields.

  • Populating selectItems with database values

    I'm looking for an example of how to populate a combo box using the selectItems tag with database records. I'd like to be able to populate the item value and item label. I am able to build an array to populate this way, but can not find a good database example. Could someone point me in the right direction?
    Thanks

    public class SQLView {
    private SQLView() { } //Prevents instantiation
    public class Field {
    public static final String id = "id";
    public static final String name = "name";
    public class ProductCategory {
    public static final String select =
    "select id, name from ProductCategory order by name";
    DataAccess.java
    public DataAccess(String confEnvName, String dataSourceName) throws Exception {
    try {
    InitialContext ic = new InitialContext();
    Context envCtx = (Context) ic.lookup(confEnvName);
    DataSource ds = (DataSource)envCtx.lookup(dataSourceName);
    name = confEnvName + '/' + dataSourceName;
    con = ds.getConnection();
    } catch (Exception ex) {
    throw new Exception("Couldn't open connection to database: " +
    dataSourceName + ' ' + ex.getMessage());
    public ResultSet getResultSet(String statement) throws SQLException {
    PreparedStatement st = con.prepareStatement(statement);
    ResultSet rs = st.executeQuery();
    return rs;
    public List resultSetToSelectItems(String statement) throws SQLException {
    List list = new ArrayList();
    ResultSet rs = getResultSet(statement);
    try {
    while (rs.next()) {
    list.add(new SelectItem(new Integer(rs.getInt(SQLView.Field.id)),
    rs.getString(SQLView.Field.name)));
    finally {
    rs.close();
    return list;
    Catalog.java
    public synchronized List getCategoryList() throws SQLException {
    if (categoryList == null) {
    categoryList = dataAccess.resultSetToSelectItems(SQLView.ProductCategory.select);
    if (!categoryList.isEmpty()) {
    categoryId = (Integer)((SelectItem)(categoryList.get(0))).getValue();
    else {
    categoryId = new Integer(0);
    return categoryList;

  • Populating table from database

    Number FoodItem Quantity Price Description
    1     Rice     1 bag     5000 Carbohydrate
    2     Beans     1 bag     4000 Protein
    3     Palm Oil 1 bottle 500 Fats & Oil
    i have a table like this in my database,need help in populating my list
    with "FoodItem" from the database when my GUI comes up.Also,want to display final result of selection in my table.
    '\n'
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    import static javax.swing.GroupLayout.Alignment.*;
    import java.sql.*;
    import java.util.*;
    public class Foodtable extends JFrame {
         //private JButton finish,view;
         private JTable table;
         private DefaultTableModel model;
         private JScrollPane pane,pane1;
         private JTextField currentamount,totalamount,qtyfield;
         private JList foodlist;
         private JComboBox box;
         private String[] qtybox={"cup","mudu","bag"};
         private DefaultListModel lm;
         Connection con=null;
         Statement st=null;
         private static ResultSet rs;
         public Foodtable(){
              JPanel p1 = new JPanel();
              p1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Food List",TitledBorder.CENTER,TitledBorder.TOP));
              p1.setLayout(null);
              p1.setPreferredSize(new Dimension(170,150));
              lm = new DefaultListModel();
              foodlist = new JList(lm);
              pane1 = new JScrollPane(foodlist);
              pane1.setBounds(10,20,148,180);
              p1.add(pane1);
              JLabel qty = new JLabel("Quantity:");
              qty.setBounds(10,210,60,20);
              p1.add(qty);
              qtyfield = new JTextField(5);
              qtyfield.setBounds(65,210,30,20);
              p1.add(qtyfield);
              box = new JComboBox(qtybox);
              box.setBounds(95,210,60,20);
              p1.add(box);
              JPanel p2 = new JPanel();
              p2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Food Table",TitledBorder.CENTER,TitledBorder.TOP));
               model = new DefaultTableModel();
               model.addColumn("Number");
               model.addColumn("Food Item");
               model.addColumn("Quantity");
               model.addColumn("Price");
               model.addColumn("Description");
              table = new JTable(model);
              pane = new JScrollPane(table);
              pane.setPreferredSize(new Dimension(300,140));
              p2.add(pane);
              JPanel p = new JPanel();
              GroupLayout layout = new GroupLayout(p);
              p.setLayout(layout);
              layout.setAutoCreateGaps(true);
              layout.setAutoCreateContainerGaps(true);
              layout.setHorizontalGroup(layout.createSequentialGroup()
                   .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                             .addComponent(p1)
                        .addComponent(p2)
              layout.setVerticalGroup(layout.createSequentialGroup()
                   .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(p1)
                        .addComponent(p2)
              JPanel p4 = new JPanel();
              p4.setLayout(null);
              p4.setPreferredSize(new Dimension(200,30));
              /*finish = new JButton("Finish");
              finish.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
              finish.setRolloverEnabled(false);
              finish.setBounds(170,20,60,20);          
              p4.add(finish);*/
              JLabel currentlabel = new JLabel("Current Amount:");
              currentlabel.setBounds(300,10,100,20);
              p4.add(currentlabel);
              currentamount = new JTextField();
              currentamount.setBounds(395,10,50,20);
              currentamount.setEditable(false);
              p4.add(currentamount);
              JLabel total = new JLabel("Amount Spent:");
              total.setBounds(300,30,100,20);
              p4.add(total);
              totalamount = new JTextField();
              totalamount.setBounds(395,30,50,20);
              totalamount.setEditable(false);
              p4.add(totalamount);
              GroupLayout flayout = new GroupLayout(getContentPane());
              getContentPane().setLayout(flayout);
              flayout.setAutoCreateGaps(true);
              flayout.setAutoCreateContainerGaps(true);
              flayout.setHorizontalGroup(flayout.createSequentialGroup()
                   .addGroup(flayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addComponent(p)
                        .addComponent(p4)
              flayout.setVerticalGroup(flayout.createSequentialGroup()
                   .addGroup(flayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addGroup(flayout.createSequentialGroup()
                             .addGroup(flayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                  .addComponent(p)
                        .addComponent(p4)
              setSize(640,460);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
         public static void main(String[] arg){
              new Foodtable().setVisible(true);
         public void showRecord(){
              try{
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   con = DriverManager.getConnection("jdbc:odbc:food","","");
                   st = con.createStatement();
                   rs=st.executeQuery("SELECT*FROM tbl_food");
                   while(rs.next()){
                        lm.addElement(rs.getString("food_name"));
              catch(Exception sqle){
                   JOptionPane.showMessageDialog(null,"Exception.......\n" + sqle.getMessage() ,"Error Information",JOptionPane.ERROR_MESSAGE);
         /*public void query(){
              try{
                   Class.forName("com.mysql.jdbc.Driver");               
                   con = DriverManager.getConnection("jdbc:mysql://localhost/food?user=password=");
                   st = con.createStatement();
                   String sql = "SELECT foodlist.food,foodlist.description FROM foodlist";
                   rs = st.executeQuery(sql);
                   while(rs.next()){
                        lm.addElement(rs.getString(1)+'\n');
              }catch(Exception ee){
                   System.out.println(ee);
              finally{
                   try{
                        st.close();
                        con.close();
                   }catch(Exception ex){ System.err.println(ex);}
         public void actionPerformed(ActionEvent e){
              Object[] value = foodlist.getSelectedValues();
              if(e.getSource()==view){
                   query();
              if(e.getSource() == move){
                   for(int i=0;i<value.length;i++){
                        String word = (String)value;
                        //String foodclass = rs.getString("foodlist.description");
                        Vector<Object> data = new Vector<Object>();
                        data.addElement(word);
                        data.addElement(qtyfield.getText()+" "+box.getSelectedItem());
                        data.addElement("");
                        //data.addElement("foodclass");
                        model.addRow(data);

    This particular forum is about jdbc. Do you have a question about jdbc?
    If so then what specifically is it?
    If you have questions about GUIs (display, buttons, events, etc) then there are other forums for that.

Maybe you are looking for

  • Advantages of using ATV Ethernet port to airport express

    Any advantages of connecting my Apple TV via Ethernet.The extended from an exteme late model express is providing 300 Mb/s. at a data rate of -51 dBm in 802.11a/n.

  • SAP to 3rd party: EDI and XI: Needed advantages and disadvantages

    HI All, I have a requirement to sent PO data from SAP to 3rd party Vendors.(more than 30 vendors). Client insists on using EDI.!! I have completed the config on SAP R/3 side and IDOCS are created in SAP R/3. Since we have XI in the landscape, I have

  • Check 64-bit jdk or not

    Hi, I am in a process of installing the WLS 10.3.6 on a 64-bit machine (Win7) and need to check if I have a 64 bit jdk which I thought I do have according to the following output (please see the windows-x86_64 in the below): C:\windows\system32>java

  • ADF: Configuration.createRootApplicationModule() generates bc4j.xcfg error

    I am using JDeveloper 11.1.1.5 to create a web service which performs mathematical calculations based on a varying number of inputs. Some of the inputs serve as criteria for querying DB tables to obtain static numerical values. This static data is th

  • Export keeps failing: QuickTime error 0

    Still having problems exporting my video. I've tried Share/DVD... to hard drive, and exporting from Compressor with DVD settings, and every time, the audio exports fine, and the video starts - but at some point it fails with a QuickTime error 0. I tr