JTree building frrom database values.

Hi,
Im building a JTree from values which are present in the database. How do I go about doing this?Presently I have retreived values from the db and have those in a HashMap. I am stuck from this point on...Can someone please help me?
Thanks in advance
Sudarshan

final DefaultMutableTreeNode root = new DefaultMutableTreeNode(new NodeInfo(" Employees","","","","","","","",""));
createNodes(root); // create nodes here
private void createNodes(DefaultMutableTreeNode root) {
  // pass in tree root node
  formConnection = null;
  Statement selectEmployees = null;
  ResultSet rs = null;
  String employee_Name;
  String middle_Name;
  String employee_ID;
  String employee_Classification;
  String employee_Photo = "";
  String employee_Branch;
  try {
    // establish your database connection
    Connection formConnection = ?????????
    selectEmployees = formConnection.createStatement();
    String employeeSelect = "select * from employees where Last_name <> 'DELETED' order by Last_name, First_name, Middle_name";
    rs = selectEmployees.executeQuery(employeeSelect);
    // Now create the tree
    while(rs.next()) {
      employee_Name = new String(rs.getString("Last_name")).trim() + " " + new String(rs.getString("First_name")).trim();
      middle_Name = new String(rs.getString("Middle_name")).trim();
      if (!middle_Name.equals("")) {employee_Name = employee_Name + ", " + middle_Name;}
      employee_ID = new String(rs.getString("Employee_ID")).trim();
      employee_Classification = new String(rs.getString("classification")).trim();
      employee_Branch = new String(rs.getString("Branch_ID")).trim();
      createEmployeeNodeSet(root, employee_ID, employee_Name, employee_Classification, employee_Photo, rs.getString("First_name").trim(), rs.getString("Middle_name").trim(), rs.getString("Last_name").trim(), employee_Branch);
    rs.close();
    // close your database connection here
  catch (Exception fieldEx) {
    // Unable to load employee tree data
private void createEmployeeNodeSet(DefaultMutableTreeNode root, String employee_ID, String employee_Name, String employee_Classification, String employee_Photo, String emp_First, String emp_Middle, String emp_Last, String emp_Branch) {
  DefaultMutableTreeNode leaf = null;
  DefaultMutableTreeNode employee = new DefaultMutableTreeNode(new NodeInfo(employee_Name,employee_ID,employee_Name,employee_Classification,employee_Photo,emp_First,emp_Middle,emp_Last,emp_Branch));
  root.add(employee);
  newNode = employee;
  for (int i = 0; i < leafCtrl.length;i++ ) {
    // here I create a set of leaf nodes for each employee (held in leafCtrl string array)- not necessary
    leaf = new DefaultMutableTreeNode(new NodeInfo((String)leafCtrl[0],employee_ID,employee_Name,employee_Classification,employee_Photo,emp_First,emp_Middle,emp_Last,emp_Branch));
employee.add(leaf);
// node I use - it has additional information I keep for other uses
private class NodeInfo {
public String nodeText; // Node display text
public String employeeID; // ID
public String employeeName; // complete name
public String employeeType; // type
public String employeePhoto; // photo info
public String employeeFirst; // first name
public String employeeMiddle; // middle name
public String employeeLast; // last name
public String employeeBranch; // current branch
public NodeInfo(String nText, String eID, String eName, String eType, String ePhoto, String eFirst, String eMiddle, String eLast, String eBranch) {
nodeText = nText;
employeeID = eID;
employeeName = eName;
employeeType = eType;
employeePhoto = ePhoto;
employeeFirst = eFirst;
employeeMiddle = eMiddle;
employeeLast = eLast;
employeeBranch = eBranch;
public String toString() {
return nodeText;
Note there is no use keeping the data in a hash map as you can keep it in the tree.
Hope this helps
rykk

Similar Messages

  • 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

  • How to check radio button as default on the basis of database value?

    Hi Friends,
    I have one jsp, in which I am having a field of radio button, which have two boolean values of 0 & 1. I want to check the radio button as default on the basis of database value, kindly help me out.
    Thanks a lot in advance. Please help me out.

    probably, when using struts you should do all your calculations in action class it self
    Eg. in jsp
    <html:radio name="myForm" property="myProperty" value="0">0</html:radio>
    <html:radio name="myForm" property="myProperty" value="1">1</html:radio>
    in Action class
    if (databaseValue == 0)myForm.setMyProperty(0);
    else if (databaseValue == 1)myForm.setMyProperty(1);
    rest will follow
    whatever be the value it will come selected

  • I Need to build a database/booking and dispatch system that intergrates with iCal, Address Book and all Apple device's What would be the best Way.

    Hi
    Can anyone give me some useful information on the best ways to design and build a database/booking & dispatch system that can be intergrated through ical, address book and available on my macbook, ipad & iphone and all accessed through icloud.
    I started my own chauffuer Service a year ago as an independent. it's becoming a massive bore that most of my time is spent taking down information, checking if i am available for clients and with alot of diary checking and repeatative entries and email ping pong and invoicing, what i want to do is concerntrate on advertising and marketing and using my time off for R & R
    What i would like to do is access my information in an app and automate most of the processes like
    assigning the job to the client with intergration through iCal and Address Book
    be able to email confirmation through mail with an invoice produced through numbers or excel
    payment is already done through payleven mobile and must be done in person so i'd rather keep that seperate to all processes apart from a tick box to say it has been paid for.
    I have been looking at all options  FileMaker, Bento, Automator, Apple Script. to be frank im no expert and am a little confused as to what to do any advice would be greatly recieved.

    Hi,
    I would suggest that is going to be an involved and complex process.
    I would personally look into some of the invoicing and time scheduling software available and see if any fit your needs.
    Take a look here: http://www.tuaw.com/2008/07/30/app-roundup-timekeeping-and-billing/
    and here: http://www.tuaw.com/2008/07/31/app-roundup-timekeeping-and-billing-part-ii-the-q uickening/
    for starters.
    Best wishes
    John M

  • How to store all database values in to a single textarea in swing

    I am trying to show my database values in to a single textarea but i cannot able to show to that textarea.. pls someone help..

    I am not shure what you are exactly meaning but you can use the setText(String text) method of JTextArea.
    Several values could be seperated with a "\n" character.
    import javax.swing.*;
    public class ImplodeTrial {
      public static void main(String[] args) {
          String[] databaseValues={"Apple", "Banana", "Orange"};
          String temp=implode(databaseValues, "\n");
          JTextArea t=new JTextArea();
           t.setText(temp);     
          JFrame j=new JFrame();
           j.getContentPane().add(t);
           j.pack();
           j.setVisible(true);
       public static String implode(String[] ary, String delim) {
             String out = "";
             for(int i=0; i<ary.length; i++) {
                 if(i!=0) { out += delim; }
                 out += ary;
         return out;

  • Build new database through scripts must understand spanish character sets.

    Hello Gurus,
    I need some simple advice, a good chance for some quick points for you.
    I have never built a database to understand any other character set other than American English. I now have to build a database that will be used for Spanish characters- keyboards, etc. But I will be using English for the 11g software install. I only wish to be able to show Spanish characters in the data for customers names.
    I will be creating the database with scripts I have made to make the standard template for database files, control files, etc.
    Then I will be importing from a dump I have done that was made with American English character sets.
    System is 11g (11.2.0.3.0) on Linux Enterprise Server 5.8.
    I was thinking to use the AL32UTF8 character set, but I am unsure where to use it.
    My original test did not show Spanish characters for customers names like the 'tilda' or 'sueano' (pardon my spelling). But in this case I did not make the exeception for Spanish, I only used the standard American English build (no changes in the init.ora file or initial database build script).
    How can I adjust my parameter file for the initial creation of the database template to be able to understand the Spanish character set and still be able to import my dump file without error.
    EXAMPLE of a build script:
    CREATE DATABASE mynewdb
    USER SYS IDENTIFIED BY sys_password
    USER SYSTEM IDENTIFIED BY system_password
    LOGFILE GROUP 1 ('/u01/app/oracle/oradata/mynewdb/redo01.log') SIZE 100M,
    GROUP 2 ('/u01/app/oracle/oradata/mynewdb/redo02.log') SIZE 100M,
    GROUP 3 ('/u01/app/oracle/oradata/mynewdb/redo03.log') SIZE 100M
    MAXLOGFILES 5
    MAXLOGMEMBERS 5
    MAXLOGHISTORY 1
    MAXDATAFILES 100
    CHARACTER SET US7ASCII
    NATIONAL CHARACTER SET AL16UTF16
    If I replace NATIONAL CHARACTER SET AL16UTF16 to AL32UTF8 will it work to show Spanish characters?
    Sorry for the long winded question, any advice will be great.
    Thankfully,
    Shawn

    Hello,
    the national charsets is for column types like nvarchar not for normal varchar data types. So if your dump file contains such column types you will also need to set it. The charset is for the normal column types like varchar. The use of unicode is best pratice if you use multiel language, but keep in mind that multibyte charset can be a problem during the import because varchar2(10) means 10byte and not 10 chars, so errors like identifier to long can occur during import.
    You can create the database.
    Check this documentation:
    http://docs.oracle.com/cd/B28359_01/server.111/b28298/ch2charset.htm
    You can use a charset like WE8MSWIN1252 which covers spanish also (as far i know) and is a superset to us7ascii
    regards
    Peter

  • How to compare, current value in :block.text_item with the database value

    Hi
    Could you please tell me
    How to compare the current value in :block.text_item with the corresponding database column value.
    I am using forms 10g
    There is block and there is an text Item in that block.
    When I run the form and query the block (tabular), the :block.text_item shows me, whatever value there in the database.
    Now I add some value in the :block.text_item to the existing value.
    now
    the :block.text_item contains old+ new added value
    whereas
    the database table contains 'old' value
    Now on a button click , I want to find out what is the value that I have added
    Could you please tell me, is it possible without writing a select query?

    Hello,
    Now on a button click , I want to find out what is the value that I have addedSo you mean always user will add value in the existing value. Because this way will fail in one case. Let say
    Value in Database is = ABCD
    User opened the form and he removed the D and write E and now value is ABCE and length is still same 4. So, there is no addition.
    Anyway you can know the database value at runtime there is one property for item called DATABASE_VALUE. It gives the value which is in database while you are running the form before save. and you can use like this..
    Trigger = WHEN-MOUSE-DOUBLE-CLICK on item level
    DECLARE
      vItemValue DATATYPE; -- Set the data type according to your desired field.
      vValueAdded DATATYPE; -- Set the data type according to your desired field.
    BEGIN
      vItemValue:=GET_ITEM_PROPERTY('ITEM_NAME',DATABASE_VALUE);  -- It will return you the database value in vItemValue variable.
      IF LENGTH(vItemValue)>LENGTH(:FORM_ITEM_NAME) THEN  -- It mean something change or added
        vValueAdded:=SUBSTR(:FORM_ITEM_NAME,LENGTH(vItemValue)+1);
        MESSAGE('Added value is : '||vValueAdded);  -- It will show you the added value.
      END IF;
      -- now suppose you want to show the old and new value in message not the added one
      -- Then no need of IF condition. You can just use message like this
      -- And i would prefer to use like this way
      MESSAGE('Old Value : '||vItemValue||'  New Value - '||:FORM_ITEM_NAME);
      MESSAGE('Old Value : '||vItemValue||'  New Value - '||:FORM_ITEM_NAME);
    END;Hope it is clear.
    -Ammad

  • Parameters - Not Filling in when using Append all database values

    Hello, I am using CR 2013 and trying to create a parameter which would be a list of organization names from a MySQL Database.  I am able to see the tables and field names no problem but when I click Append all database values I get the circle and nothing appears.   It should be noted I can see a list of values in the "Select Expert" for that same table and field.
    I am running a Windows 7 machine.
    Please let me know if you have any suggestions or solutions.
    Thanks,
    Peter LaMont

    are you using win 7 sp1 or higher as per the supported platforms. you probably are but have to ask.
    i would recommend trying to create a new report off of the same db and try to use a dcp again. if that doesn't work, can you create a dcp (using a new report) off of a different database type...e.g. ms access?
    is anyone else in your environment having the same issue?
    if none of the above work it's most likely an install issue and you may wish to try an update of cr finding the latest sp here..

  • How to build dynamic databases(record set) for mobile?

    Hi All ,
    i have an applocation that needs to personalize the data for users .
    i have the data available , but dont know how to personalize it fot users to download special version of my application.
    how to build dynamic databases(record set) for mobile?

    In the load rule in the dimension build settings you would need to go to the tab dimension definition, choose the time dimension and right click on it. Select Edit properties. If you have not done so, set the dimension to be the time dimension. Then go to the generations/levels tab and set the generation names you need. For example if you want YTD, you would set the generation name to Year, if you want QTD set it to Quarter. You would set the number to the generation number that coorisponds to the generation. The DBAG has the list of names for all of the DTS members.

  • Populating Database values into a combo box in STRUTS Framework

    Hi Guys,
    I am currently working on a STRUTS Framework project and I can't get much resources related to the problems that I'm facing.
    Currently I need to populate a JSP file's Combo box with database values. What I don't know here is the syntax used to in STRUTS framework to populate the Combo box with database values. Anyone with experience related to this topic, please kindly help me out.

    Struts doesn't define anything about the datab layer. You're free to implement how you will.
    Struts instead guides you into following an MVC pattern.
    You populate a combo box with values from a bean.
    So you need to set up a bean for this page to talk to.
    That bean can be populated from the database - but at that point you're in java/jdbc code - and away from the struts layer.
    My suggestions
    1 - Define a bean to represent the information from the database.
    2 - write a method that queries the database, and copies the data into a List of those beans. This will be your Data access layer.
    3 - in your action, call that method, and then set the list of beans as a request attribute. Or maybe as a property on a form.
    4 - use that list of beans to populate your dropdown box.

  • For Update framework of AIR Application,I want preserve databases value when i update lates download

    for Update framework of AIR Application, I want preserve databases when i update lates download ,Right now when i ta
    ke latest from server it will remove my database  value and i i want ot preserve my database value.
    Please any one can guide me in this?

    Ya it is in Application directory...
    in windows  :: D:\FlexWorkSpaceSVN\YSIPrototype\bin-debug\data\YSIDB.db
    Thanks
    Sunil

  • Getting Error of SqlBuildTask fail while building the database project

    Hi Experts,
      I am getting error while building the database project in following manner please help on this.
    Error 803 04018: The "SqlBuildTask" task failed unexpectedly.
    System.NullReferenceException: Object reference not set to an instance of an object.
       at Microsoft.Data.Tools.Schema.UserInteractionServices.GetElementName(IModelElement element, ElementNameDetails details)
       at Microsoft.Data.Tools.Schema.Sql.SqlUserInteractionServices.GetElementName(IModelElement element, ElementNameDetails details)
       at Microsoft.Data.Tools.Schema.Sql.Sql110UserInteractionServices.GetElementName(IModelElement element, ElementNameDetails details)
       at Microsoft.Data.Tools.Schema.Sql.Validation.MismatchedNameRule.Analyze(SqlSchemaModel sqlSchemaModel, ISqlModelElement sqlElement, SqlRuleSetting ruleSetting, SqlRuleExecutionContext context)
       at Microsoft.Data.Tools.Schema.Sql.Validation.SqlValidationRuleProxy.Analyze(SqlSchemaModel sqlSchemaModel, ISqlModelElement sqlModelElement, SqlRuleSetting ruleSetting, SqlRuleExecutionContext context)
       at Microsoft.Data.Tools.Schema.Sql.Validation.SqlValidationRule.Analyze(SqlRuleSetting ruleSetting, SqlRuleExecutionContext context)
       at Microsoft.Data.Tools.Schema.Sql.RuleEngine.SqlRuleEngine.ExecuteRuleImpl(SqlRuleSetting ruleSetting, SqlRuleExecutionContext context, Predicate`1 suppressProblem, IEnumerable`1& errors)
       at Microsoft.Data.Tools.Schema.Sql.RuleEngine.SqlRuleEngine.ExecuteRules(SqlSchemaModel dataSchemaModel, IEnumerable`1 ruleSettings, IEnumerable`1& errors, Predicate`1 suppressProblem, Func`1 executeCanceled)
       at Microsoft.Data.Tools.Schema.Sql.RuleEngine.SqlRuleEngine.ExecuteRules(SqlSchemaModel dataSchemaModel, IEnumerable`1 rules, IEnumerable`1& errors, Predicate`1 suppressProblem, Func`1 executeCanceled)
       at Microsoft.Data.Tools.Schema.Sql.Build.SqlTaskHost.RunBuildValidation(SqlSchemaModel model, ErrorManager errorContainer, Func`1 buildCanceledQuery, HashSet`1 includedRuleIDs, HashSet`1 excludedRuleIDs)
       at Microsoft.Data.Tools.Schema.Sql.Build.SqlTaskHost.OnRunBuildValidations(ErrorManager errorManager, HashSet`1 includedRuleIds)
       at Microsoft.Data.Tools.Schema.Sql.Build.SqlTaskHost.RunBuildValidations(ErrorManager errorManager, HashSet`1 includedRuleIDs)
       at Microsoft.Data.Tools.Schema.Tasks.Sql.TaskHostLoader.LoadImpl(ITaskHost providedHost, TaskLoggingHelper providedLogger, Boolean runAllBuildTimeValidationRules)
       at Microsoft.Data.Tools.Schema.Tasks.Sql.TaskHostLoader.Load(ITaskHost providedHost, TaskLoggingHelper providedLogger, Boolean runAllBuildTimeValidationRules)
       at Microsoft.Data.Tools.Schema.Tasks.Sql.SqlBuildTask.ExecuteLoadTaskHostStep()
       at Microsoft.Data.Tools.Schema.Tasks.Sql.SqlBuildTask.ExecuteStep(Func`1 step)
       at Microsoft.Data.Tools.Schema.Tasks.Sql.SqlBuildTask.Execute()
       at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
       at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext() C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets 547 5 ABC_DB
    Niraj Sevalkar

    Hi Niraj, does this happen for all projects or for one specific project? I'd love to understand if this is a specific bug or if it might be a setup issue. 
    If this issues is reproduceable on the latest SSDT bits, I'd suggest capturing the event log for what is going wrong and then opening a connect
    bug for this issue at https://connect.microsoft.com/SQLServer/feedback/CreateFeedback.aspx and
    use the category "Developer Tools(SSDT, BIDS, etc.)". We're trying to track all bugs through connect so that you can tell when we have fixed the issue and we can request
    more information. Please include the event log (instructions on this below) plus any other useful information you can provide, such as an example of exact steps to reproduce the problem.
    Gathering an Event Log for SSDT
    For diagnostic purposes we would like you to gather an event log for the issue that you are experiencing in SSDT. In order to gather a log and send it to a member of
    the team, please follow the steps below.
    Open a new command prompt as Administrator.
    Run the following command
    logman create trace -n DacFxDebug -p "Microsoft-SQLServerDataTools" 0x800 -o "%LOCALAPPDATA%\DacFxDebug.etl" -ets
    logman create trace -n SSDTDebug -p "Microsoft-SQLServerDataToolsVS" 0x800 -o "%LOCALAPPDATA%\SSDTDebug.etl" -ets
    Run whatever the target/issue scenario is in SSDT.
    Go back to the command prompt and run the following commands
    logman stop DacFxDebug -ets
    logman stop SSDTDebug -ets
    The resulting ETL files will be located at %LOCALAPPDATA%\SSDTDebug.etl & %LOCALAPPDATA%\DacFxDebug.etl and can be navigated to using Windows Explorer.
    Please attach this file when creating the connect bug
    NOTE - These logs will only be used by Microsoft product team members in order to better diagnose the problem you are experiencing
    with SSDT and will not be shared elsewhere. If you want to make sure that there is no private information in your ETL file, the SSDTDebug.etl file can be opened and analyzed using the Windows Event Viewer.
    To do this, open the Windows Event Viewer application. In the right-hand panel, select Open Saved Log. Navigate to the location where you saved the log, open, and review
    the contents of the trace.
    Thanks,
    Kevin

  • Can I build a database, using my Contacts and then email them?

    Can I build a database, using my Contacts and then email them?

    If you mean email them as a group you need to get a group messaging app first. If you mean email the database you need to take a screen shot and email the photo.

  • How to view database values from server to client

    hi friends
    i have database in server side, i am storing values to the database from client side machine through remote methods. But now i need to view the database values from the server side. how to do this using RMI.
    Plz give me suggestion.
    by
    vinod

    Why do you have to use RMI for this task? That way you've got to write both a client and a server. Just use JDBC directly from the server.

  • Is there a way where I can give an HTML File  and pass database values to it?

    Hello,
    I have a Report that has Complex Layout with different Fonts,sizes etc.
    After designing it in Front Page, the HTML Source comes to be around 180 KB. Portal Reports with Custom Layout fail to get this size of layout code( seems the limit is around 32KB).
    Writing my own stored Package using htp/htf calls, but still I needed to paste this entire 180KB Code and replace the layout names with database names. This works fine but the readability of this code is ugly.
    Is there a way where I can feed the database values as parameters along with the HTML File to pick substitute and then
    show me the output?
    Thank you.
    Madhav

    you can use dynamic pages!

Maybe you are looking for

  • Mdis settings

    Hi all We are doing a port load and want to auto map and add values to a qualified lookup table during the import we have to following setting in out ini Automap Unmapped Value=Yes Unmapped Value Handling=Add Always Use Unmapped Value Handling=Add Th

  • Menu bar with file, edit and view are still there not the new drop down new file bar

    downloaded the new version of firefox and the new drop down menu bar that has file,edit,view and history, stuff like that is still there. i have what looks like a broken photo or missing picture square

  • JVM for Intel PXA250

    Hi NG, i have some different vm's(jeode, J9, Creme, Superwaba). These works with a lot processors, but as far as i know, they don't support an intel pxa250. Is this processor for example, similar with StrongArm? I would be glad, if someone is in this

  • Copies of old receipts

    Got a new iphone this weekend, and one of the games I play (football manager) needs a copy of the original receipt for the game forwarded to them so they can (apparently) associate it with the new phone. I, of course, don't have a copy of that receip

  • Apple refuses to do a repaid/replace my ipad 2 back cover, why?

    Hi everyone, I just brought my ipad2 to the Apple store in Annapolis, MD asking for a replacement for the back cover (of cause I argree to pay for the cost). They said that they do not do any hardware repair on the ipad2. So all I can do is that to p