Tree View with database

Tree View with database


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 Tutorials/Questions & Answers:
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
tree view  display a tree view in flex?nodes will be in the form
Advertisements
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 - 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
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
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
ModuleNotFoundError: No module named 'django-tree-view'
ModuleNotFoundError: No module named 'django-tree-view'  Hi, My... named 'django-tree-view' How to remove the ModuleNotFoundError: No module named 'django-tree-view' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'mptt-tree-view'
ModuleNotFoundError: No module named 'mptt-tree-view'  Hi, My... named 'mptt-tree-view' How to remove the ModuleNotFoundError: No module named 'mptt-tree-view' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-tree-view'
ModuleNotFoundError: No module named 'django-tree-view'  Hi, My... named 'django-tree-view' How to remove the ModuleNotFoundError: No module named 'django-tree-view' error? Thanks   Hi, In your
Version of com.semanticcms>semanticcms-view-tree dependency
List of Version of com.semanticcms>semanticcms-view-tree dependency
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
Maven Dependency semanticcms-view-tree >> 1.0
You should include the dependency code given in this page to add Maven Dependency of com.semanticcms >> semanticcms-view-tree version1.0 in your project
ModuleNotFoundError: No module named 'django-database-view'
ModuleNotFoundError: No module named 'django-database-view'  Hi...: No module named 'django-database-view' How to remove the ModuleNotFoundError: No module named 'django-database-view' error? Thanks   Hi
Maven Repository/Dependency: com.semanticcms | semanticcms-view-tree
Maven Repository/Dependency of Group ID com.semanticcms and Artifact ID semanticcms-view-tree. Latest version of com.semanticcms:semanticcms-view-tree dependencies. # Version Release Date
com.semanticcms - semanticcms-view-tree version 1.4.2 Maven dependency. How to use semanticcms-view-tree version 1.4.2 in pom.xml?
com.semanticcms  - Version 1.4.2 of semanticcms-view-tree Maven...-tree in pom.xml? How to use semanticcms-view-tree version 1.4.2 in pom.xml? Learn... com.semanticcms  - Version 1.4.2 of semanticcms-view-tree in project by the help
com.semanticcms - semanticcms-view-tree version 1.4.1 Maven dependency. How to use semanticcms-view-tree version 1.4.1 in pom.xml?
com.semanticcms  - Version 1.4.1 of semanticcms-view-tree Maven...-tree in pom.xml? How to use semanticcms-view-tree version 1.4.1 in pom.xml? Learn... com.semanticcms  - Version 1.4.1 of semanticcms-view-tree in project by the help
view
view  what is the use view in database
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
Maven dependency for com.semanticcms - semanticcms-view-tree version 1.6.0 is released. Learn to use semanticcms-view-tree version 1.6.0 in Maven based Java projects
of semanticcms-view-tree released The developers of   com.semanticcms - semanticcms-view-tree project have released the latest version of this library on 18 Jul 2021, the released version of  com.semanticcms - semanticcms-view-tree
Maven dependency for com.semanticcms - semanticcms-view-tree version 1.5.1 is released. Learn to use semanticcms-view-tree version 1.5.1 in Maven based Java projects
of semanticcms-view-tree released The developers of   com.semanticcms - semanticcms-view-tree project have released the latest version of this library on 19 Mar 2021, the released version of  com.semanticcms - semanticcms-view-tree
Maven dependency for com.semanticcms - semanticcms-view-tree version 1.6.1 is released. Learn to use semanticcms-view-tree version 1.6.1 in Maven based Java projects
of semanticcms-view-tree released The developers of   com.semanticcms - semanticcms-view-tree project have released the latest version of this library on 15 May 2022, the released version of  com.semanticcms - semanticcms-view-tree
Maven dependency for com.semanticcms - semanticcms-view-tree version 1.5.0 is released. Learn to use semanticcms-view-tree version 1.5.0 in Maven based Java projects
of semanticcms-view-tree released The developers of   com.semanticcms - semanticcms-view-tree project have released the latest version of this library on 30 Mar 2020, the released version of  com.semanticcms - semanticcms-view-tree
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
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
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
Tree
Tree  print("code sample");1) Write Java code to create the following tree using new Tree state- ments: 1
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for semanticcms-view-tree version 1.4.4
-view-tree version 1.4.4. You can add these depency in your project to get com.semanticcms:semanticcms-view-tree:1.4.4 Java library in your project.. Maven...-view-tree version 1.4.4 In this section have given the dependency code
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for semanticcms-view-tree version 1.4.3
-view-tree version 1.4.3. You can add these depency in your project to get com.semanticcms:semanticcms-view-tree:1.4.3 Java library in your project.. Maven...-view-tree version 1.4.3 In this section have given the dependency code
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for semanticcms-view-tree version 1.4.2
-view-tree version 1.4.2. You can add these depency in your project to get com.semanticcms:semanticcms-view-tree:1.4.2 Java library in your project.. Maven...-view-tree version 1.4.2 In this section have given the dependency code
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for semanticcms-view-tree version 1.4.1
-view-tree version 1.4.1. You can add these depency in your project to get com.semanticcms:semanticcms-view-tree:1.4.1 Java library in your project.. Maven...-view-tree version 1.4.1 In this section have given the dependency code
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for semanticcms-view-tree version 1.4.0
-view-tree version 1.4.0. You can add these depency in your project to get com.semanticcms:semanticcms-view-tree:1.4.0 Java library in your project.. Maven...-view-tree version 1.4.0 In this section have given the dependency code
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for semanticcms-view-tree version 1.3
-view-tree version 1.3. You can add these depency in your project to get com.semanticcms:semanticcms-view-tree:1.3 Java library in your project.. Maven...-view-tree version 1.3 In this section have given the dependency code for Maven
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for semanticcms-view-tree version 1.2
-view-tree version 1.2. You can add these depency in your project to get com.semanticcms:semanticcms-view-tree:1.2 Java library in your project.. Maven...-view-tree version 1.2 In this section have given the dependency code for Maven
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for semanticcms-view-tree version 1.1
-view-tree version 1.1. You can add these depency in your project to get com.semanticcms:semanticcms-view-tree:1.1 Java library in your project.. Maven...-view-tree version 1.1 In this section have given the dependency code for Maven
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for semanticcms-view-tree version 1.0
-view-tree version 1.0. You can add these depency in your project to get com.semanticcms:semanticcms-view-tree:1.0 Java library in your project.. Maven...-view-tree version 1.0 In this section have given the dependency code for Maven
Retrive data from database and perform binary tree operations on that data in jsp or java
Retrive data from database and perform binary tree operations on that data... from database dynamically and perform operations on that. Just like calculate Left and Subbinary tree node count. Check balanced tree of particular Id ,unbalaced
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
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
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
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
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
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
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
database
database  database
database
database  database application
database
database  the code for initializing the database connection
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

Ads