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

Similar Messages

  • 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

  • Jtree examples of populating data from database

    I have searched many of the solutions here, but the threads that contain examples of jtree loading from an sql database are not available. Does anyone have a good example of populating a jTree from the database?
    Thank You

    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

  • Problem while populating data from database dynamically.

    I am having two combo box
    First one displays list of table Names
    Second one displays list of the corresponding field Names.
    Now when the user selects the table name the corresponding field names appear in the second combo box & now when the user selects the field name then the requirement is to get the data of the corressponding field of the table on the screen on the button click.
    I want to do this thing dynamically through coding.
    My requirement is only the data of those columns that have been queried should appear on the screen whereas other column data should not appear.
    Can any body help me out.

    I'm not sure if you want to populate the combobox dynamically based on any selected data source.
    If so it is kind of tricky, but do-able. You need to write little bit of coding yourself.
    First you need to get the Database metadata. For details see
    http://java.sun.com/j2se/1.4.2/docs/api/java/sql/DatabaseMetaData.html
    where you can get the table names.
    Then using the result set metadata of the selected table you can get the column information. For details see
    http://java.sun.com/j2se/1.4.2/docs/api/java/sql/ResultSetMetaData.html
    If you want to display the data of selected table and column value (statically filled combo box), then it is easy.
    you can create your own SQL statement based on the selected tabe and column and set it to the rowset dynamically in the code (may be in the method beforerenderresponse).
    - Winston

  • I just got a new phone today the iphone 5c and i plugged it into itunes. i wanted to get all of my data from my iphone 4s but when i synced my phone all of my iphone 3 data was on my new phone how do i get my iphone 4 data on my new phone?

    I just got a new phone today the iphone 5c and i plugged it into itunes. i wanted to get all of my data from my iphone 4s but when i synced my phone all of my iphone 3 data was on my new phone how do i get my iphone 4 data on my new phone?

    Did you choose the wrong back up? There should be a drop box when you go to "Restore from Back up" in iTunes and your iPhone is plugged in, on the Summary page. Choose the correct back up. If you can't find one, and you still have your device, back up your iPhone 4 again and then choose that back up. Or check for an old iCloud back up if you have one.

  • My time machine does not want to save any more the data from my powerbook 13" Snow Leopard; i get the message "Time Machine could not suppress the disk image of saving "Volumes/Time Capsule Disk/PowerBook _2011_03_21_123627 sparsebundle" What should I do?

    My time machine does not want to save any more the data from my powerbook 13" Snow Leopard; i get the message "Time Machine could not suppress the disk image of saving "Volumes/Time Capsule Disk/PowerBook _2011_03_21_123627 sparsebundle" What is the problem? What should I do?
    Thanks !!
    Alain

    Could that read " . . . could not access . . ."?  If so, try repairing your backups, per #A5 in Time Machine - Troubleshooting.
    If not, or if that doesn't help, see #A1 there. Use the TM Buddy widget it details to copy and post the messages here.

  • I want to transfer some of the data from an intel 2006 iMac running 10.4.11 to a 2011 iMac running 10.6.8

    I want to transfer some of the data from an intel 2006 iMac running 10.4.11 to a 2011 iMac running 10.6.8. What is the best way?

    It depends on what you have. The options include:
    1. Connect them with a FireWire cable and start up with old iMac with the T key held down.
    2. Copy the files over a network.
    3. Copy the files to an external drive. Some files require the volume to be formatted as Mac OS Extended.
    (117837)

  • I want to be able to enter data from my pc to my ipod touch

    I want to be able to enter data from my pc to my ipod touch.  Pleas advise if possible, and what app or progran i need.

    Not sure if there's an app for Windows. Pages (a word processing app) is available for the Mac and iPod Touch, iPhone and iPad and  it fits your requirement.

  • This is my first mac product and i want to restore my backed up data from my forma PC to my new mac. how do i do it?

    this is my first mac product and i want to restore my backed up data from my forma PC to my new mac. how do i do it?

    Migrate your Windows files or system to your Mac

  • Problem in populating jtable data from database

    hi,
    i am using JTable to retrieve data from database and show it in table. JTable
    is working fine with static data. but while retrieving from databse its giving a NullPointerException at getColumnClass() method. Below is complete source code. plzz help.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.sql.*;
    import javax.swing.table.*;
    /*jdbc connection class*/
    class connect
    Connection con;
    Statement stat;
    public connect()throws Exception
    Class.forName("org.postgresql.Driver");
    con=DriverManager.getConnection("jdbc:postgresql://localhost/dl","dl","dl");
    stat=con.createStatement();
    public ResultSet rsf(String rsstr)throws Exception
    ResultSet rs=stat.executeQuery(rsstr);
    return rs;
    public void upf(String upstr)throws Exception
    stat.executeUpdate(upstr);
    class MyTableModel extends AbstractTableModel
    private String[] columnNames = {"name","id","dep","cat","rem","chkout"};
    Object[][] data;
    public MyTableModel()
    try{
    connect conn=new connect();
    ResultSet rs3=conn.rsf("select * from usertab");
    ResultSetMetaData rsmd=rs3.getMetaData();
    int col=rsmd.getColumnCount();
    int cou=0;while(rs3.next()){cou++;}
    data=new Object[cou][col];
    System.out.println(cou+" "+col);
    ResultSet rs2=conn.rsf("select * from usertab");
    int i=0;int j=0;
    for(i=0;i<cou;i++)
    rs2.next();
    for(j=0;j<col;j++)
    data[i][j]=rs2.getString(getColumnName(j));
    System.out.println(data[0][2]);
    }catch(Exception e){System.out.println("DFD "+e);}
            public int getColumnCount() {
                return columnNames.length;
            public int getRowCount() {
                return data.length;
            public String getColumnName(int col) {
                return columnNames[col];
            public Object getValueAt(int row, int col) {
                return data[row][col];
           public Class getColumnClass(int c) {
              return getValueAt(0, c).getClass();
            public boolean isCellEditable(int row, int col) {
                if (col < 2) {
                    return false;
                } else {
                    return true;
            public void setValueAt(Object value, int row, int col) {
                data[row][col] = value;
                fireTableCellUpdated(row, col);
    class MyFrame extends JFrame
    public MyFrame()
         setSize(600,500);
         JPanel p1=new JPanel();
         p1.setBackground(new Color(198,232,189));
         JTable table = new JTable(new MyTableModel());
         table.setPreferredScrollableViewportSize(new Dimension(500,200));
         table.setBackground(new Color(198,232,189));
         JScrollPane scrollPane = new JScrollPane(table);
         scrollPane.setBackground(new Color(198,232,189));
         p1.add(scrollPane);
         getContentPane().add(p1);
    /*Main Class*/
    class test2
         public static void main(String args[])
         MyFrame fr =new MyFrame();
         fr.setVisible(true);
    }thanx

    hi nickelb,
    i had returned Object.class in the getColumnClass() method. But then i
    got NullPointerException at getRowCount() method. i could understand that the
    main problem is in data[][] object. In all the methods its returning null values as it is so declared outside the construtor. But if i declare the object inside the constructor, then the methods could not recognize the object. it seems i cant do the either ways. hope u understood the problem.
    thanx

  • How do i add data from database to JTable ! Urgent

    How do i add data from database to the columns of JTable?.

    hi,
    Thanks for ur link. but this is just a part of my application which i am developing user interface in swing package for which i want to know how to show data to user in the table format where by table input data will be from the database. say something like todays activity is shown to the user in table format... So u have any idea of how to do this...

  • Urgent help with simple BPEL process for reading data from database

    Hello there,
    I need help with BPEL project.
    i have created a table Employee in Database.
    I did create application, BPEL project and connection to the database properly using Database Adapter.
    I need to read the records from the database and convert into xml fomat and it should to go approval for BPM worklist.
    Can someone please describe me step by step what i need to do.
    Thx,
    Dps

    I have created a table in Database with data like Empno,name,salary,comments.
    I created Database Connection in jsp page and connecting to BPEL process.
    It initiates the process and it goes automatically for approval.
    Please refer the code once which i created.
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <%@page import="java.util.Map" %>
    <%@page import="com.oracle.bpel.client.Locator" %>
    <%@page import="com.oracle.bpel.client.NormalizedMessage" %>
    <%@page import="com.oracle.bpel.client.delivery.IDeliveryService" %>
    <%@page import="javax.naming.Context" %>
    <%@page import="java.util.Hashtable" %>
    <%@page import="java.util.HashMap" %>
    <%@ page import="java.sql.*"%>
    <%@ page import= "jspprj.DBCon"%>
    <html>
    <head>
    <title>Invoke CreditRatingService</title>
    </head>
    <body>
    <%
    DBCon dbcon=new DBCon();
    Connection conn=dbcon.createConnection();
    Statement st=null;
    PreparedStatement pstmt=null;
    Hashtable env= new Hashtable();
    ResultSet rs = null;
    Map payload =null;
    try
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory");
    env.put(Context.PROVIDER_URL, "opmn:ormi://localhost:port:home/orabpel");//bpel server
    env.put("java.naming.security.principal", "username");
    env.put("java.naming.security.credentials", "password");//bpel console
    Locator locator = new Locator("default","password",env);
    IDeliveryService deliveryService =
    (IDeliveryService)locator.lookupService(IDeliveryService.SERVICE_NAME );
    // construct the normalized message and send to Oracle BPEL Process Manager
    NormalizedMessage nm = new NormalizedMessage();
    java.util.HashMap map = new HashMap();
    st=conn.createStatement();
    out.println("connected");
    String query1="Select * from EMPLOYEE";
    rs=st.executeQuery(query1);
    /*reading Data From Database and converting into XML format
    so that no need of going to BPEL console and entering the details.
    while (rs.next()){
    String xml1 = "<AsynchBPELProcess1ProcessRequest xmlns='http://xmlns.oracle.com/AsynchBPELProcess1'>"+
    "<Empno>"+rs.getString(1)+"</Empno>"+
    "<EmpName>"+rs.getString(2)+"</EmpName>"+
    "<Salary>"+rs.getString(3)+"</Salary>"+
    "<Comments>"+rs.getString(4)+"</Comments>"+
    "</AsynchBPELProcess1ProcessRequest>";
    out.println(xml1);
    nm.addPart("payload", xml1 );
    // EmployeeApprovalProcess is the BPEL process in which human task is implemented
    deliveryService.post("EmployeeApprovalProcess", "initiate", nm);
    // payload = res.getPayload();
    out.println( "BPELProcess CreditRatingService executed!<br>" );
    // out.println( "Credit Rating is " + payload.get("payload") );
    //Incase there is an exception while invoking the first server invoke the second server i.e lsgpas13.
    catch(Exception ee) {
    //("BPEL Server lsgpas14 invoking error.\n"+ee.toString());
    %>
    </body>
    </html>
    Its working fine.And i want it for Bulk approvals.please help me step by step procedure if any other way to implement this.

  • How to populate Adobe LiveCycle Designer generated  PDF Forms with data from Database in Windows app

    Hi
    I have a PDF template designed in Adobe LiveCycle Designer. This template has form fields which needs to be filled with data programmatically. I am using windows application in C#.Net 2005 in which I want to retrieve data from database and merge this data into PDF form in respective fields.
    How this can be achieved?
    I searched a lot & I found that we can process the XDP file generated from PDF to acheive this. I created the XDP file out of the PDF template created in designer. But I don't know how to merge data from database into that XDP file in respective fields and again convert this XDP file back to PDF programmatically. Can anybody help me ? This is urgent.
    Thanks in advance.
    Sambhaji

    Please ignore the above code.<br />The following one is correct one.<br />using System;<br />using System.Data;<br />using System.Configuration;<br />using System.Web;<br />using System.Web.Security;<br />using System.Web.UI;<br />using System.Web.UI.WebControls;<br />using System.Web.UI.WebControls.WebParts;<br />using System.Web.UI.HtmlControls;<br />using System.Text;<br />public partial class _Default : System.Web.UI.Page <br />{<br />    protected void Page_Load(object sender, EventArgs e)<br />    {<br />        Response.ContentType = "application/vnd.adobe.xdp+xml";<br />        StringBuilder responseString = new StringBuilder();<br />        responseString.Append("<?xml version='1.0' encoding='UTF-8'?>");<br />        responseString.Append("<?xfa generator='AdobeLiveCycleDesigner_V8.0' APIVersion='2.5.6290.0'?>");<br />        responseString.Append("<xdp:xdp xmlns:xdp='http://ns.adobe.com/xdp/'>");<br />        responseString.Append("<xfa:datasets xmlns:xfa='http://www.xfa.org/schema/xfa-data/1.0/'>");<br />        responseString.Append("<xfa:data>");<br /><br />        responseString.Append("<form1>");<br />        responseString.Append("<TextField1>Homer</TextField1>");<br />        responseString.Append("<TextField2>Simpson</TextField2>");<br />        responseString.Append("<field name ='DropDownList1'>");<br />        responseString.Append("<items save='1'>");<br />        responseString.Append("<text>1</text>");<br />        responseString.Append("<text>2</text>");<br />        responseString.Append("<text>3</text>");<br />        responseString.Append("</items>");<br />        responseString.Append("</field>");<br /><br />        responseString.Append("</form1>");<br /><br />        responseString.Append("</xfa:data>");<br />        responseString.Append("</xfa:datasets>");<br />        responseString.Append("<pdf  href='C:\\Test.pdf' xmlns='http://ns.adobe.com/xdp/pdf/' />");<br />        responseString.Append("</xdp:xdp>");<br /><br />        Response.Write(responseString);<br />        Response.Flush();<br />        Response.End();<br />    }<br />}

  • How to display data from Database individually??? Anyone can help ?

    HI,
    i i had select a row of data from database using ,
    /* Query * From Table RESOURCEORDER where po = selected no and project = selected project */
         public ResultSet getAllData() throws SQLException
         getConnection();
         Statement stmt = conn.createStatement();
         ResultSet rs = stmt.executeQuery("SELECT * FROM RESOURCEORDER WHERE PROJECT = '" + getSelProject() + "' and PURCHASEORDERNO = '" + getPo() + "'" );
         return rs;
    After that , how do i display the data individually ?
    Eg select data is ('projectA','7891203-1', '10-4-2005','lcd',2000,'121-45217-8','electrical','pending','donwong')
    i want to display them individually, like this in a page
    Projectname: /* should display the Project A*/
    P.O no:
    Date:
    Order:
    Cost:
    Acc no:
    Type:
    status:
    Orderedby:
    Can anyone help ? cos i'm new to JSP ......Thanks alot!!!!!
    Regards,
    khim

    I assume PO being a unique key, will always return 1 row from db.
    public String[] getAllData() throws Exception
    getConnection();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT * FROM RESOURCEORDER WHERE PROJECT = '" + getSelProject() + "' and PURCHASEORDERNO = '" + getPo() + "'" );
    String [] returnValue = new String[9];
    while(rs.next())
    returnValue[1] = rs.getString("colname");
    returnValue[2] = rs.getString("colname");
    ///and so on
    return returnValue;
    }Once you get that you could individually view it by setting a loop to run through the returned array.
    Hope it helps

  • How to fetch data from database in javafx 2.2 table which is editable.

    Dears!
    I want to fetch data from database in javafx 2.2 tableformat with jdbc , which is also editable and i can add more records in this table also.
    Can anybody help me

    I can vaguely recall some sort of JavaFX database connectivity feature, I'm not sure if it's valid anymore.The link is based on JavaFX Composer which only applied to NetBeans 6.9 and JavaFX 1.x (both of which are now dead techs).
    There is a good chance you will have to write your own. There are several blogs describing other peoples' work. You could probably use them as a reference.Here is Narayan's basic [url http://blog.ngopal.com.np/2011/10/19/dyanmic-tableview-data-from-database/] tutorial for displaying data from a database in a TableView, you'll need to look elsewhere for the editing portion.
    The [url http://docs.oracle.com/javafx/2/ui_controls/table-view.htm]JavaFX TableView tutorial gives info about how to handle edits in a TableView, but you will need to tie the updates back to the database yourself.
    It is possible that [url http://www.javafxdata.org/]DataFX may provide some facilities to help support you.

Maybe you are looking for

  • How do I get apps to show up in the "passbook" folder?

    I'm new to iPhone, and want to be able to use the "passbook" folder.  I've installed several of the free "apps for passbook" on my phone, and figured all I had to do was to drag  them to the "passbook" folder.  When I did that, I wound up with the ap

  • SSO implemention in distributed environment / BO SDK

    Hi All, I am working on Single Sign On (SSO)  implementation. I have Jboss Application Server which my web application resides and Business objects is resides on other Server SSO is implemented in the Business Objects Server. I can open the CMC from

  • How To Enable Samba And SWAT In Solaris 10

    Link: http://bensweb.no-ip.info/ultrasparc/samba.htm This is a short and simple guide that I wrote for new Solaris users who want to get Samba and SWAT up and running quickly. (It works with SPARC and x86.) Enjoy!

  • LINE IN COLUMN

    Hi, I have two tables : - test (id_test, test) - val_test (id_val_test, val_test, id_test) id_test is the foreign key My data are : test : 1 test1 val_test : 1 val1 1 2 val2 1 3 val3 1 So if i made a joint, i have 1 val1 1 1 val2 2 1 val3 3 And i wan

  • Problems with BT Home Hub Phone 2.1 help!

    I've been having problems with my Hub phone 2.1 handset for weeks now. A catalougue of woes: 1. It doesn't ring properly with incoming calls- It starts to ring but then there's a horrible highpitched feedback noise and then the handset resets itself.