kashi said:
ya what u done its correct , how to do in DB send me the query's for
the above table . how to create and retrieving .
Have you studied SQL? There is a statement called "CREATE TABLE". It is
mostly the same, but not quite, between different versions of SQL.
Relational database management systems (RDMBS) have slightly different syntax
for their commands. They are similar, though. In each one you have to decide
the type of each column in a table. Without knowing the details of what
information you will store in the table, and therefore what each column will
contain and represent, it is impossible to answer your question.
What RDBMS do you plan to use? I prefer PostgreSQL myself. Many people like
MySQL, now owned by Sun. Apache Derby comes with Java now, in the JDK, where
it is called "Java DB". Oracle, IBM DB2 and Microsoft SQL Server all provide
free versions of their database products, with certain restrictions. And
those are just the free ones.
Using a common version of the syntax to create a table, I would implement
RedGrittyBrick's example:
ID NAME PARENT_ID
>
> A Alex NULL
> B Bob A
> C Cath A
> ...
> M Moe C
> ...
something like this:
CREATE TABLE person
(
id CHAR(1) PRIMARY KEY,
name VARCHAR(100) NOT NULL,
parent_id CHAR(1) FOREIGN KEY REFERENCES person (id)
);
CREATE INDEX ON person (name);
CREATE INDEX ON person (parent_id);
INSERT INTO person (id, name) VALUES ( 'A', 'Alex');
etc.
What queries you write depends on what you want to find out. One typical
query might be:
SELECT id, name FROM person WHERE parent_id IS NULL ORDER BY id;
The number of queries you could write, or would want to, even for this simple
and not very practical table is quite large.
In Java, you would use JDBC to encapsulate those queries, send them to the
database, and recover the results into your program. Look at the 'java.sql'
package, and types like 'PreparedStatement'.
You have a good deal of studying ahead of you. Besides the documentation for
the database system you use (such as Derby / Java DB), there are good
tutorials at the java.sun.com site. IBM DeveloperWorks is another good web site.
By the way, the word "you" is not spelled "u".