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).

Similar Messages

  • 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

  • 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

  • Building jtree from database query

    I am trying to build a JTREE from a database result-set. The resultset is listed below. I'm thinking I can somehow build a dynamic array of objects to build a TreePath, then use that to build the JTREE. Any input is appreciated.
    ResultSet Output:
    Here is how the results would be retrieved from the database (including the order of the output).
    usr 1
    local 2
    sbin 2 file4
    bin 3 file1
    bin 3 file2
    logs 3 file3
    tmpdir 4
    The first column is the directory name, the second column is the directory/file level/position, and the third column is the filename, if one exists.
    So from above:
    /usr/local/sbin has file "file4"
    /usr/local/bin has files "file1" and "file2"
    /usr/local/logs has file "file3" and directory "tmpdir"
    How could I gather this information into an appropriate structure and create a JTREE from it.
    Thanks.
    -Jim

    So each line would:basically...
    If I don't know the entire path of the parent (because I've read in a
    line that only has the "one-up" parent name) .... However, when I
    read the line from the database result-set, I don't know where "local" is.See... that's another problem with that data. Maybe you know cuz it's the last node if it's all in a proper order. In which case maybe you only need to hold the last parent node... Some recursive function would be useful.
    If I were going to store the data, I would store either the name as a full path:
    /usr
    /usr/local
    /usr/loca/bin
    or
    usr /
    local /usr
    bin /usr/local
    If you have that, it might be easier to figure out without having to worry about what belongs where.

  • 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

  • Jtree from database

    hii all,
    Does any one know hw to populate a Jtree from a database.pls hlep me with an example.
    thanx

    Hi there,
    Im having exactly the same problem. If you find out, please let me know, and I will do the same for you.
    Thanks
    Simon

  • 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!

  • 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

  • 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.

  • 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

  • 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 selectOneChoice  from database

    Hi Everyone .
    l am new to JDeveloper and ADF . l need help to populate list of countries from the database to selectOneChoice object using managed bean . The database contains all the countries but l cant load the data into dropdownlist .
    Thank you
    Khuluza

    Hi,
    You can use List of values feature in your View Object (VO) with countries table as data source. And select UI Hints as Choice List.
    When you drag this VO from data control to faces, you can view the field will be rendered as a choice list.
    Thanks.
    - LSR

  • 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

  • Constructing Jtree with data from Database

    Hi
    I am new to JTree and I need some help. My problem goes like this. I have a table in the data base which has data like Folder_Nr, Folder_Name, Folder_Prev_Nr, Folder_Typ_Nr, Folder_Access.
    If the Folder_Nr is 1 and folder_prev_nr =0, then it is a root folder and if folder no is 3 and folder_prev_no is 1 then it is a sub folder of the Folder_Nr 1. and so on is the data. I need to present all these folders in a JTree and be able to dynamically add and delete folders.
    It will be of great help if anyone can provide me with some lead or some source code.
    Thanking u in advance
    BalaaP

    Yes,using LiveCycle you could accomplish this easily.Once you have your invoice form ready based on predefined XSD, you can easily update the form data by fetching the values from database using JDBC operation.Also you could email this updated form using Email service.
    Thanks,
    Wasil

  • How i can enter information from Database to jtree and update it

    How i can enter information from Database to jtree and update it

    Is the memory cache enabled (about:cache)?<br />
    You can open about: pages via the location bar like you open a website.
    *http://kb.mozillazine.org/browser.cache.memory.enable

Maybe you are looking for