JTree, displaying data from a database

Hi, im doing an application that will display the listing of courses, and allow users to book them. For the display of courses, i plan to use JTree to display them.
However my problem arises from fetchin data and putting them into the tree.
This file connects to the database and fetch the 'Course Category' and puts it in an Array.
public ArrayList<CourseCategory> getCategory() {
ArrayList<CourseCategory> categoryArray = new ArrayList();
try {
String statement = "SELECT * FROM Category";
rs = stmt.executeQuery(statement);
while (rs.next()) {
CourseCategory cc = new CourseCategory();
cc.setCategoryID(rs.getInt("CategoryID"));
cc.setCategoryName(rs.getString("CategoryName"));
categoryArray.add(cc);
rs.close();
stmt.close();
con.close();
catch (Exception e) {
//catch exception     }
return categoryArray;
CourseCategory File has the necessary accessor methods, and a toString method to display out the category name.
The main file, which has the JTree
public DisplayCoursesGUI() {
try {
courseDB = new CourseDB();
courseDB.getCategory();
catch (Exception e) {
//catch exception }
DefaultMutableTreeNode top = new DefaultMutableTreeNode("");
for (int i=0;i<courseDB.test2().size();i++) {
category = new DefaultMutableTreeNode(courseDB.getCategory());
top.add(category);
Codes for JTrees as follows.
I have the output of
e.g.
[MICROSOFT OFFICE APPLICATIONS, WEB APPLICATIONS] repeated twice in the tree. Im hoping to achieve the following effects
e.g.
-MICROSOFT OFFICE APPLICATIONS
----Microsoft Word
----Microsoft Powerpoint
-WEB APPLICATIONS
-----Adobe Photoshop
I have 2 MS Access Table.[Category]ID, CategoryName. [COURSE]ID,CourseName,CategoryID. They have a relationship.
How do I modify my codes to get what i hope to achieve? Help really appreciated.
Thank you!!

Hi,
If you read my first post, I wanted to achieve this effect.
----CategoryName1
----------SubCategoryItem1
----CategoryName2
----------SubCategoryItem2
My Table Structure.
CATEGORY TABLE
ID (autonumber), Name(string)
COURSES TABLE
ID(autonumber),Name(string), CategoryID(int)(A Relationship is link to Category Table-ID)
I have managed to retrieve the items from the Category Table into a result set, and I have added the result set into an Array (See 1st post)
Now, the problem comes when im tryin to do a for loop to display out the categorynames from the array(see 1st post again).
Now my array prints out as follows
e.g.
[CategoryName1,CategoryName2]
And if i put a for look into my application to display a JTREE,
My end results is
------[CategoryName1, CategoryName2]
------[CategoryName1, CategoryName2]
How should I ammend my codes to get:
-------CategoryName1
-------CategoryName2

Similar Messages

  • Walkthrough: Displaying Data from Oracle database in a Windows application.

    This article is intended to illustrate one of the most common business scenarios such as displaying data from Oracle database on a form in a Windows application using DataSet objects and .NET Framework Data Provider for Oracle.
    You can read more at http://www.c-sharpcorner.com/UploadFile/john_charles/WalkthroughDisplayingDataOracleWindowsapplication05242007142059PM/WalkthroughDisplayingDataOracleWindowsapplication.aspx
    Enjoy my article.

    hi,
    this is the code :
    public class TableBean {
    Connection con ;
    Statement ps;
    ResultSet rs;
    private List perInfoAll = new ArrayList();
    public List getperInfoAll() {
    int i = 0;
    try
    con = DriverManager.getConnection("url","root","root");
    ps = con.createStatement();
    rs = ps.executeQuery("select * from user");
    while(rs.next()){
    System.out.println(rs.getString(1));
    perInfoAll.add(i,new perInfo(rs.getString(1),rs.getString(2),rs.getString(3)));
    i++;
    catch (Exception e)
    System.out.println("Error Data : " + e.getMessage());
    return perInfoAll;
    public class perInfo {
    String uname;
    String firstName;
    String lastName;
    public perInfo(String firstName,String lastName,String uname) {
    this.uname = uname;
    this.firstName = firstName;
    this.lastName = lastName;
    public String getUname() {
    return uname;
    public String getFirstName() {
    return firstName;
    public String getLastName() {
    return lastName;
    ADF table code:
    <af:table value="#{tableBean.perInfoAll}" var="row"
    binding="#{backing_Display.table1}" id="table1">
    <af:column sortable="false" headerText=""
    align="start">
    <af:outputText value="#{row.firstName"/>//---> Jdeveloper 11g doesn't allow me to use this.. it says firstName is an unknown property..
    </af:column>
    </af:table>
    Please tell me is this the way to do it.. or is it a must to use the DataCollection from the data controls panel...
    Thanks...

  • How to display data from a database to a  JComboBox  JTextField

    Hello
    I was wondering I have a database called "PAYTYPE" and have a colums called
    EMPLOYEETYPE     PAYBASIC     PAYSUNDAY     PAYHOLIDAY     PAYPERIOD
    What i want to do is display the list of EMPLOYEETYPE in a combo box(Which i got this part working),
         try{
              ResultSet rs = db.getResult("Select * FROM PAYTYPE");
              while(rs.next())
                   payTypeField.addItem(rs.getString(2));
              }catch(SQLException e)
              }When an item is selected from the combo box then the information thats in PAYBASIC,PAYSUNDAY,PAYHOLIDAY, PAYPERIOD will be displayed in textfields
    this is the problem im trying to solve
    Any Ideas ??????

    What im trying to do is the following
    on my Gui i have 1 JComboBox and 3 JtextFields
    The Jcombo box is populated by the data base
    try{     
              ResultSet rs = db.getResult("Select * FROM EMPLOYEEPAYTYPE");
              while(rs.next())
                   payTypeField.addItem(rs.getString(2));
              }catch(SQLException e)
              }Now that i have the JComboBox filled I want the other 3 JTextField to be populated with the information that been selected by the JComboBox
    I under stand there needs to be a .addActionListener(this) to the JComboBox
                    payTypeField = new JComboBox();
                payTypeField.setBounds(130, 10,100,20);
                payTypeField.addActionListener(this);
                payTypeField.addItemListener(this);
                 c.add(payTypeField);I would just like the steps that i need to take in order to fill the JTextBoxes in pudoscode
    The information that i need will need to be pulled from the database - EMPLOYEEPAYTYPE
    Thanks
    Jon

  • Displaying data from a Database control

              I'm retrieving data from a sybase database into a java class and then pass that
              through to my jsp page. This works fine, as long as the sql actually returns a
              value (This specific query only returns one or none records).
              If no records were found, my jsp page displays an error message "Caught exception
              when evaluating expression "{pageFlow.m_dates.mon_am_loc}" with available binding
              contexts [actionForm, pageFlow, globalApp, request, session, appication, pageContext,
              bundle, container, url, pageInput]. Root cause: knex.scripting.javascript.EvaluatorException:
              The undefined value has no properties."
              the call in my .jsp looks as follow : <netui:label value="{pageFlow.m_dates.mon_am_loc}"
              escapeWhiteSpaceForHtml="false"/>
              .... and is part of a repeter item tag.
              Any help would be appreciated.
              

    Hi Jothivenkatesh M,
    Place the cursor in forst field and press  CNT+y now select the entair row by using your mouce and press CNT+C and paste the data in what ever position.
    Plzz rewad if it is useful,
    Mahi.

  • How to display data from mySQL database as a graph?

    I am working in DW, is there any function to insert graphs from recordset?

    My webpage is in php, don't tell me i have to work in coldfusion in order to display my data from mySQL graphically.
    Look at this link: http://www.adobe.com/devnet/coldfusion/articles/basic_chart.html

  • Querying and displaying data from a database

    Hi,
    The environment I am working in has the EBIZR12 suite installed on the apps server APP1, the EBIZR12 database deployed to server DB1 listening on port 1522 and a MIDTIER database deployed to server DB1 listening on port 1521. I have a custom page that needs to query the data off of MIDTIER and populate a display table. The page I have created emulates that of the Search tutorial. I have an application module that contains a BC4J object and views and these are connecting to the MIDTIER to retrieve data. It has a table that should display queries returned from the MIDTIER database. My question is, are there any limitations with OA framework development and deployment that would NOT make this feasible? if not is there anything else I would need to do either as a pre-requisite or as part of my page construction to make this work, because currently my page table is not being populated and I am not getting any exceptions on the page to indicate the database is either unreachable or the connection configurations are incorrect. Any help is very much appreciated.
    regards,

    Yes, in case of query region, an executequery was getting called on clicking go button. But now as you just have a table mapped to a VO, you also need to call the executequery explicitly in the page controller's processRequest method.
    Your point "I would like to point out that the instructions in those tutorials are not compatible with the newest version of JDEV" is completely wrong. First of all each Jdev has its own set of tutorials reflecting all the changes in that particular version. Secondly, as you are trying to use a particular scenario steps to create something different, you can't expect it to handle all the side off scenarios you can make. Drag and drop UI won't get you more than a few basic screens. Read more and you will understand the working of framework.
    --Shiv                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Displaying data from database using AJAX

    Hi,
    I have a table that holds data from a database, on each row I have a hyperlink.
    When the user presses the hyperlink the table drops down and displays some additional data,I am trying to display another table of data based on the ID of the row selected. As the second table holds a lot of data I was hoping to use AJAX. Does anybody know of any good tutorials or how to retrieve data from a database based on the ID of the row for .jspx pages.
    Regards
    Steve

    Hi Steve,
    Follow the steps below to achieve what you want:
    a. Specify actionListener for the commandlink component, when the user clicks it invokes the actionListener method in the backing bean(in which you can get the id of the selected row from the ActionEvent), perform the call to your database and fetch the data required for the second table
    b. Set PartialTriggers property of second table to the id of the command link
    Hope this helps.
    Sireesha

  • Arabic data from Sybase database fails to display correctly in Crystal Reports XI

    Post Author: shajad
    CA Forum: Crystal Reports
    In Crystal Reports XI, reports created with a ODBC (SQL server) connection to a Sybase data source fails to show Arabic data correctly. Arabic data is stored in Sybase under character set Windows-1256, but fails to display as Arabic in Crystal Reports 10. Some junk values like 'ÕæÑÉÇáÓÌá ÇáÊÌÇÑí ÓÇÑíÉÇáãÝÚæá'  appears in the report.
    How can I resolve this issue? Please help me with a solution.

    Hi Raju
    Please let us know the following information:
    - Exact version of Crystal Reports.
    - The type and the version of the database.
    - Connection i.e. ODBC, OLEDB or Native used to connect your database with Crystal Reports.
    - Are you able to create and refresh newly created report using the same database?
    - If you are using ODBC connection, please download the SQLCON32 test utility and try to fetch the data from the database using the query from the "Show SQL" from Crystal Reports and let us know the outcome.
    Hope this helps!
    Thanks

  • Displaying data from database using Repeater

    Hi,
    I have created a database with 3 column in a table.Where column 1 is username and column 2 is Report name.
    Column 1 has 2 user :-
    user1-----> ABC
    user2-----> PQR. So if i select ABC i am getting 2 records from Report based on ABC and if i select PQR i get 1 record from Report based on PQR.Till here i have done
    Now I am using repeater control and binding the data from the database.but the problem is I want hyperlink on the data which is populating.Since i am using repeater,i am able to fetch 2 records for Report.I want hyperlink on it so i am using anchor tag with
    href,Now both the records are redirecting to the same page.I want each record should redirect to different page.Please help me if any one know about these.
    Thansk Regards,
    Simanchal

    Hi,
    Base on your description here:
    "I want hyperlink on it so i am using anchor tag with href,Now both the records are redirecting to the same page"
    I agree with Bob you have to consult this issue on this forum:
    http://forums.asp.net/24.aspx/1?Web+Forms+Data+Controls
    Regards,
    Barry Wang
    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.

  • Display data from CSV file in iWeb page

    Hi,
    I like to display data from a CSV file in iWeb page if a date value from CSV file matches todays value from the system. Here is an example.
    CSV data values
    01/20/2011,Sunny,87
    01/21/2011,Cloudy,100
    01/22/2011,Rainy,60
    If today's date value is 01/21/2011 the page should display 01/21/2011 Cloudy 100 in a tabular format.
    Appreciate your help in providing HTML code for this issue.
    Thanks

    I suspect there is a soft return in the excel database somewhere that can't be seen. Take the csv/txt file into notepad and look for a line that starts oddly compared to the others.
    I haven't had luck removing soft returns from excel files so I do this a rather odd way. I take the excel file into InDesign as a table, and then use find/change to replace any soft returns with nothing, then convert the text to table and then export the text out again by going export, and selecting text from the dropdown menu.
    For my money, I always save tab delimited text files from excel so that if a field does contain commas, it doesn't "trick" indesign into thinking a new field is beginning or not... instead the field delimiters are tabs and they are unlikely to have been used in the excel database.
    If you do choose to use this indesign import method of mine to clean up the database, i also noticed two things in your screengrab: first was that some fields have spaces at the start of the text... easy enough to fix with a GREP that looks for ^\s (start of a sentence followed by a space) and replace with nothing. The second thing is the T&C field that all entries (at least in the screengrab) all start the same – if all entries in the database start the same, couldn't that line be in the indesign file? Its only a small detail I know.

  • Error while retriving the data from the database

    morning we shutdown and start up the server.after that when i am retreving the data from the database it is giving the following error.
    ora-04030: out of process memory when trying to allocate 64512 bytes(sort subheap,sort key)
    pga_aggregate_target details are as follows
    value=2147483648
    display value=2g
    is default=false
    is sesmodifiable=false
    hash=2184567208

    Please look at the following link :
    how solve  ORA-04030: out of process memory when trying to allocate
    Cheers!

  • How to retrieve the data from SAP database.

    Hi Pals,
    How to retrieve data from SAP R/3 System to my third party software. I will make my query little bit more clear. There is a list of assets entered and stored in the SAP system. For example 3 mobile phones.
    1) Mobile 1- Nokia
    2) Mobile 2 - Samsung
    3) Mobile 3 u2013 Sony
    Now think I do not know what all assets is there. I have to retrieve the data and get it on my third party software. Just display the list of assets. Lets say SAP XI is also there. Now how will I map it and get the details.
    Please give me step by step method.
    N.B: Just to read the data from SAP database.
    Please make the flow clear step by step.
    Thanking you
    AK

    Hi,
    You can use RFC or ABAP Proxy to make synchronous call with SAP.
    Under RFC or ABAP Proxy Program you can get the data from SAP tables. Direct access to SAP Database is not preferrable even if its possible.
    The better way to go for RFC or PROXY.
    You will send the request from Third party system and the it will be as input parameters from RFC/ Proxy it will response based on it.
    This got it all..
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/5474f19e-0701-0010-4eaa-97c4f78dbf9b
    /people/siva.maranani/blog/2005/09/03/invoke-webservices-using-sapxi
    /people/stefan.grube/blog/2006/09/21/using-the-soap-inbound-channel-of-the-integration-engine
    /people/arpit.seth/blog/2005/06/27/rfc-scenario-using-bpm--starter-kit - File to RFC
    HTTP to RFC - A Starter Kit
    /people/community.user/blog/2006/12/12/http-to-rfc--a-starter-kit
    Refer
    Thanks
    Swarup
    Edited by: Swarup Sawant on Jun 4, 2008 9:32 AM

  • Getting Data From MySQL Database using Dreamweaver CS4 Built In Functions

    Hi,
    I am really in need of some help if you don't mind.
    I basically have a website with user regsitration system etc and so on.
    I basically connected to my Data Base in Dreamweaver CS4 and now want to use the tools in Dremweaver CS4 to display Data from database.
    Problem is i see the tools but not really sure how i use them. I see on Data bar all the tools to view, update delete records etc.
    I basically created a page where i want to display all the records in the DB. I done this using dynamic data selecting what fields to display etc and 15 records per page.
    When i view the page in localhost thou it is only showing 1 record althou i have like 5 users in my test db.
    So if anyone can really tell me how i go about displaying data from db that be great. When i learn how to do that i probably will understand and learn how to update records etc.
    Thanks

    To display all records, you need to apply a repeat region to the paragraph, div, or table row that contains the dynamic text objects for the database results. You might also find it helpful to follow the dynamic application tutorial in the Adobe Developer Connection.

  • Use an applet in a Jsp to display data from Oracle DB

    Hi everyone, I'm very new to java my question is:
    Is there a way to display an applet like a table within a Jsp to display data from a Oracle DB? The thing is that I would be able to show this applet only at the click of the submit button in my html form.
    Please help me any sample code are welcome
    Thank you in advance
    Fabry

    Hi,
    Why can't you use a Java Bean which takes the data from the database. Then call this bean from the JSP page using <jsp:useBean> tag.
    Ok,if you dont want a Java Bean and if you want to use an applet in a JSP file, you will have to use <jsp:plugin>tag. Here is an example
    <html><head><title> Demo Applet</title></head>
    <body bgcolor="rd">
    <% if (request.getParameter("SUBMIT") != null) {%>
    <jsp:plugin type="applet" code="DemoApplet.java" codebase="." name="Demo" height="400 with="300>
    <jsp:fallback> Plug in not supported by your browser</jsp:fallback>
    </jsp:plugin>
    </body></html>
    Hope this will help you.
    Rgds,
    Ravi Shankar

  • Failed to retrieve data from the database Database Vendor Code: 2812

    Hi everyone
    Im using Sap Business One Version 2007A SP00 PL49, SQL 2005 and Crystal Reports Basic for Sap Business One (Add on 2.0.0.7). Whenever i try to generate a report from SBO the system displays the following message "Failed to retrieve data from the database DETAILS: [Database Vendor Code: 2812]"
    The scenario is that, according to the Colombia's product local expert, Is not possible to create Stored Procedures, Views, Functions or anything in the customer productive database, in order to improve the performance of the query i created other DB where i created an stored procedure, after that, i called it from Crystal where it's working ok. But when i try to generate it from SBO it show the message promted.
    Someone knows what could be happening
    I'll be thankful

    Hi Cesar,
    Please post your question to the Business One forum.
    I can't move this thread.
    Thank you
    Don

Maybe you are looking for