Home Answers Viewqa Java-Beginners Tree View with database

 
 


Amit Chauhan
Tree View with database
2 Answer(s)      2 years and 10 months ago
Posted in : Java Beginners


Hi,

I'm working with Swing.I have to construct a SplitPane with JTree on the leftside and its details which is stored in the database on the right side of the pane.
For ex:

Network
|
|Node1
| |
| |Slot1
| |
| |Line1
| |Line2
|Node2

I have stored the Node Details,Slot details,line details in database(separate table) like Node_name,id..

Now, my problem is, If I click the Node "Node1", it has to display the database details for that corresponding Node in that right side of the pane. Similarly for other nodes also..

How to write code for this? How to connect JTree with database.(MySql).

Give 1 suggestion for this plz...

Thanks
View Answers

August 3, 2010 at 6:01 PM


Hi Friend,

Try the following code:

import javax.swing.*;
import javax.swing.tree.*;
import java.sql.*;
import java.awt.*;
import java.util.*;
import javax.swing.event.*;


public class JTreeDatabase {

public static void main(String[] args){
JFrame frame = new Database();
frame.show();
}
}
class Database extends JFrame implements TreeSelectionListener{
JTextArea description;
public Database(){
setSize(400, 300);
DefaultMutableTreeNode parent = new DefaultMutableTreeNode("Students", true);
DefaultMutableTreeNode n1 = new DefaultMutableTreeNode("1");
DefaultMutableTreeNode n2 = new DefaultMutableTreeNode("2");
DefaultMutableTreeNode n3 = new DefaultMutableTreeNode("3");
DefaultMutableTreeNode n4 = new DefaultMutableTreeNode("4");
DefaultMutableTreeNode n5 = new DefaultMutableTreeNode("5");
DefaultMutableTreeNode n6 = new DefaultMutableTreeNode("6");
parent.add(n1);
parent.add(n2);
parent.add(n3);
parent.add(n4);
parent.add(n5);
parent.add(n6);

JTree tree = new JTree(parent);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addTreeSelectionListener(this);
description = new JTextArea();
JSplitPane innerPane= new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, tree, description);
getContentPane().add(innerPane, "Center");

}
public void valueChanged(TreeSelectionEvent se) {
JTree tree = (JTree) se.getSource();
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
String selectedNodeName = selectedNode.toString();
try{
Class.forName( "com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test";, "root", "root");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("Select * from student where rollNo='"+selectedNodeName+"'");
String data="";
while (rs.next()) {
data=rs.getString("name")+" "+rs.getString("address")+" "+rs.getString("age");
}
description.setText(data);
}
catch(Exception e){}

}


}

Thanks

March 13, 2012 at 7:24 PM


i want tree view structuer total table data will display so pleas help me

Now, my problem is, If I click the Node "folder", it has to display database table details for that corresponding table in that right side of the pane. Similarly for other tablesalso..









Related Pages:
tree view - Java Beginners
tree view   I m using swing for the treeview in my application and also the database(Hsqldb). I want to connect the tree view with the database fields. If u want more clarification ,let me know. Thanks
Tree View with database - Java Beginners
Tree View with database   Hi, I'm working with Swing.I have... in the database on the right side of the pane. For ex: Network | |Node1... I have stored the Node Details,Slot details,line details in database
tree view - Java Beginners
tree view  Hello Deepak, Thanks for your help last time regarding java. I have another problem, Actually I want a tree view in my application which will display the files
Populate Menus In Tree View - Struts
" as prefix.In the same way i am thinking to bring the menus in a tree view in my application "is it possible to bring menu that is stored in a database in a tree...Populate Menus In Tree View  Hi all, i am writing one simple
JSP tree view - JSP-Servlet
JSP tree view  Hi... In my project i need to display the data from database in the form of tree structure... i.e. like horizontal binary tree I've to dynamically get the values... Can you plssssss suggest me how
tree view
tree view  display a tree view in flex?nodes will be in the form
view
view  what is the use view in database
tree view - Java Beginners
tree view  I want to use tree view in my example code to display data in hierarchical form. how ?? Thanks   Hi friend, Please visit the following links: http://www.roseindia.net/java/example/java/swing
view
view  hi iam writing some struts application by using dyanafalidator form in place of actionform bean classes i can enter data by using some jsp file and it will insert to database by using business logic. now my requirement
Reg: Tree view in Struts using ajax - Struts
Reg: Tree view in Struts using ajax  HI all, Can you figure out the tree and treenode attribute belong to which .jar file or tld ? Example... the example on it. Example for Tree view in Struts to visit this link.. http
Nitobi Tree
coding and effort. Nitobi Tree adds just like folder view in Windows...Nitobi Tree       Nitobi Tree Nitobi Tree, the Ajax component of User Interface Suite is used
What is View?
one or more existing database tables or other views. In effect every view...What is View?  What is View?   Hi, A SQL View is a virtual table, which is based on SQL SELECT query. Essentially a view is very close
where do I find the fix for tree view catalog not expanding and collapsing correctly for roseindia shopping cart 1.1
where do I find the fix for tree view catalog not expanding and collapsing correctly for roseindia shopping cart 1.1  where do I find the fix for tree view catalog not expanding and collapsing correctly for roseindia shopping
DOJO Tree - Ajax
-support/dynamic-tree-database Thanks...DOJO Tree  Hi I am able to generate a Tree structure using DOJO.... But I want to give hyperlink on the each child item of that tree structure, which
tree menu delete node
tree menu delete node  I have crated a tree menu having various sub nodes now i want to delete parent node and also want to delete sub nodes when... then its subnodes are not delteting from database
Database
Database  How to represent data from database in a tree?   Please visit the following link: Retrieve data from database in tree using Java Swing
Tree
Tree  print("code sample");1) Write Java code to create the following tree using new Tree state- ments: 1
tree tag in struts2 - Struts
tree tag in struts2  I have an arraylist of values retrieved from the database and i want all the values in the arraylist to be viewed in a subtree node. like:::: COUNTRYLIST has values INDIA,UK,USA. INDIA,UK,USA
SQL Create View
  A view shows updated records. The database recreate the data using... SQL Create View       A View is a imaginary and virtual table in SQL. In SQL, a view
REGARDING TREE STRUCTURE IN STRUTS - Struts
in the database should be shown in the jsp(struts) as an tree structure form...REGARDING TREE STRUCTURE IN STRUTS  Hello friends, I need ur help its urgent requirement. I need a dynamic tree structure format i.e I have created
pre view of image uploaded
pre view of image uploaded  I am uploading a file through input type="file" in html form. I want to display preview of that uploaded image... database I don't want with ajax, jquery,php
pre view of image uploaded
pre view of image uploaded  I am uploading a file through in html form. I want to display preview of that uploaded image in the same form using java script only.. and I want to insert that image into oracle database I don't want
pre view of image uploaded
pre view of image uploaded  I am uploading a file through input in html form. I want to display preview of that uploaded image in the same form using java script only.. and I want to insert that image into oracle database I
Balance multi-way tree implimentation reating database - Java Beginners
database like Access,MySQL.As we know database is based on Balance multi-way tree...Balance multi-way tree implimentation reating database  I am doning a project in which I have to create a database product in java where user can
Creating Database using B+Tree in Java - Java Beginners
Creating Database using B+Tree in Java  I'm doing a project in which I have to create an Object Oriented Database using B+Tree in Java..It is not a Database connectivity..I have to create a seperate Database(like Oeacle)my-self
view data from database using drop down list
view data from database using drop down list  hi i want to view the data from database by selecting a value in a drop down list. for an example drop down list have picture element.when click it select pictures from the database
Save profile and image to mysql database, and view the image in another jsp page
Save profile and image to mysql database, and view the image in another jsp page  Pls. need help in saving the profile info with the image in mysql database.. some basic code pls in jsp... thanks in advance
Database
Database  is it possible to view the query code after executing it.if yes tell me the procedure.   Yes, if you want to retrieve the data that is stored in database, then use the given query: select * from student
How to view database for user when they login in netbeans and mysql?
How to view database for user when they login in netbeans and mysql?  I create a web page where when user login they have to fill in a form, after... database with jdbc connection. thanks for your help
Database
Database  hi i don't know any thing about database please help me and explain it for me . thank you   you can get more data base programs from here View Programs here
Tree Control in Flex4
Tree Control in Flex4: The Tree control is used for a hierarchical data which is expandable in tree format. It has a leaf or branch node of the item. A leaf... to expose children. The tag of Tree Control is <mx:Tree>. Example
SQL Create View
  A view shows updated records. The database recreate the data using... SQL Create View       A View is a imaginary and virtual table in SQL. In SQL, a view
Creating Tree Structure using GWT
are described below:- final Label label = new Label("Click the Node to view Tree... Creating Tree Structure using GWT       This example describes the Basics for building the Tree
grid view in java - Java Beginners
grid view in java  Is it possible to create dynamic grid view to display data from database. if yes. how ??   Hi Friend, Yes, you can. Try the following: import java.awt.*; import java.sql.*; import
Display Records in Tree Format - JSP-Servlet
Display Records in Tree Format   hi i want to displays data in the tree format with root nodes, child nodes and leaf nodes in a jsp file. The data is from database and once we select a perticular leaf node and click submit
JSP: View Session
JSP: View Session          The view consists of the Html page or the jsp components that provide the user interface. View is what we see. It is mainly
View Photo From Db MySql
View Photo From Db MySql  Good Morning Sir, Please help me, I make a small code but i have a error. I want to make viewer photo from database MySql into my project in netbeans. this is my code : try
Separate column for the navigation tree in AdvancedDataGrid
Separate column for the navigation tree in AdvancedDataGrid : In this example display a hierarchical data in AdvancedDataGrid but the navigation tree has...;s:Panel title="Separate Column for the navigation tree
View the mysql querys by and my Php WebApp
View the mysql querys by and my Php WebApp  i need to debug a php web application. The problem is somewhere in the mysql query section. I need... by the mysql database. How can i do that ? Is there some script like phpmyadmin has
Database programming - Java Beginners
Database programming  How to do a Database programing with Balanced Multiway Tree(B+ Tree,not Binary Tree) in java
Shorting Table View By Column Name
Shorting Table View By Column Name This tutorial explains how to shorting table view by column name from the database in JSP and Servlet. This example... database and table in mysql that is used in this example. create
Navigation Tree icon and labels in AdvancedDataGrid
Navigation Tree icon and labels in AdvancedDataGrid in Flex4: In this example you can see how we can change the label and icon of the navigation tree... and label of the tree. These are following: defaultLeafIcon, disclouserCloseIcon
Spanning Tree
Spanning Tree  hii, What is a spanning Tree?   hello, A spanning tree is a tree associated with a network. All the nodes of the graph appear on the tree once. A minimum spanning tree is a spanning tree organized so
binary tree
binary tree  how to count no. of nodes in a binary tree for mlm if it complet tree or incomplet tree in php using mysql db
Binary tree
Binary tree  hii, What is binary tree?   hello, A binary tree is a tree in which every node has exactly two links i.e left and right link
Binary tree
Binary tree  a. Construct a method to implement a binary tree using an array. b. Implement the binary tree to store numbers in sorted order
i want to protect mysql database table which user can not view to table and can not copy my table till then us
i want to protect mysql database table which user can not view to table and can not copy my table till then us  i want to protect mysql database table which user can not view to table and can not copy my table till then user do
binary tree
binary tree  can a binary tree be implemented with out comparing...://www.roseindia.net/java/java-get-example/java-binary-tree-code.shtml http://www.roseindia.net/java/java-get-example/java-binary-tree-insert.shtml
i want to protect mysql database table which user can not view to table and can not copy my table till then us
i want to protect mysql database table which user can not view to table and can not copy my table till then us  i want to protect mysql database table which user can not view to table and can not copy my table till then user do

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.