?
Solved

database in server?important please

Posted on 2003-02-22
23
Medium Priority
?
231 Views
Last Modified: 2013-11-23
can any expert help me on this stage,because iam new in java world,iam using java application to build up my server program and iam stuck on how to store data in hashtable class,i will attach my server console coding..
if you please run this program and let me know what is missing...
after this stage what suppose i do,
i would like to know step by step?

thankyou and appreciated your assistant.
NOTE: iam not using java swing..



         // Importing java libraries.
import java.awt.*;
import java.awt.event.*;

          // Extending the application frame and implementing ActionListener to preform actions
public class youServer extends Frame implements ActionListener{


          // Definig variables
    private TextField TF1,TF2,TF3,TF4,TF5;
    private Button    B1;
            Label     L1, L2, L3, L4, L5, L6;
            Font      F1, F2, F3, F4, F5, F6;
            Panel     P1, P2, P3, P4, P5, P6;
    public youServer() {


          // Giving a label to the frame
        super("---------------------------------------------------------A Book Shop Storing System-------------------------------------------------------");

          // Building the server GUI which consist of 5 TextFields and a Button
          // Setting the overall layout of a frame with 7 panels
          setLayout(new GridLayout(7,1));
          P1 = new Panel();
          add(P1);
          P2 = new Panel();
          add(P2);
          P3 = new Panel();
          add(P3);
          P4 = new Panel();
          add(P4);
          P5 = new Panel();
          add(P5);
          P6 = new Panel();
          add(P6);

          // Setting the layout of panel 1 with one Label
          P1.setLayout(new FlowLayout(FlowLayout.LEFT));
          L1= new Label("Enter The Book Details To The Database And Then Press Update:");
          L1.setForeground(Color.blue);
          F1 = new Font("Helvitica",Font.BOLD,20);
          L1.setFont(F1);
          P1.add(L1);


          // Setting the layout of panel 2 with one Label and a TextField
          P2.setLayout(new FlowLayout(FlowLayout.LEFT));
          L2  = new Label("Title:      ");
          L2.setForeground(Color.orange);
          TF1 = new TextField(14);
          F2 = new Font("Helvitica",Font.BOLD,15);
          L2.setFont(F2);
          P2.add(L2);
          P2.add(TF1);



          // Setting the layout of panel 3 with one Label and a TextField
          P3.setLayout(new FlowLayout(FlowLayout.LEFT));
          L3  = new Label("ISBN:     ");
          L3.setForeground(Color.orange);
          TF2 = new TextField(14);
          F3 = new Font("Helvitica",Font.BOLD,15);
          L3.setFont(F3);
          P3.add(L3);
          P3.add(TF2);

          // Setting the layout of panel 4 with one Label and a TextField
          P4.setLayout(new FlowLayout(FlowLayout.LEFT));
          L4  = new Label("Author:   ");
          L4.setForeground(Color.orange);
          TF3 = new TextField(14);
          F4 = new Font("Helvitica",Font.BOLD,15);
          L4.setFont(F4);
          P4.add(L4);
          P4.add(TF3);

          // Setting the layout of panel 5 with one Label and a TextField
          P5.setLayout(new FlowLayout(FlowLayout.LEFT));
          L5  = new Label("Quantity: ");
          L5.setForeground(Color.orange);
          TF4 = new TextField(14);
          F5 = new Font("Helvitica",Font.BOLD,15);
          L5.setFont(F5);
          P5.add(L5);
          P5.add(TF4);

          // Setting the layout of panel 6 with one Label, a TextField and a Button
          P6.setLayout(new FlowLayout(FlowLayout.LEFT));
          L6  = new Label("Price £:   ");
          L6.setForeground(Color.orange);
          TF5 = new TextField(14);
          F6 = new Font("Helvitica",Font.BOLD,15);
          L6.setFont(F6);
          P6.add(L6);
          P6.add(TF5);
          B1 = new Button("Update");
          // Adding ActoinListener to Button B1
          B1.addActionListener(this);
          P6.add(B1);

          //seting the size of the frame
          setSize(new Dimension(600, 500));

          // show the GUI
          show();                 // Visible the frame as TRUE
      }
public static void main(String[] args) {
           // use the constructor to build the GUI,creating an object called server
           youServer server = new youServer();

      }


public void actionPerformed(ActionEvent e) {

      }
      }
0
Comment
Question by:sara_uk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 8
  • 4
  • +1
23 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 100 total points
ID: 8000947
I don't know what you want us to say. An obvious thing is you need some way of closing the window, so add

       addWindowListener(new WindowAdapter(){
         public void windowClosing(WindowEvent e){
           System.exit(0);
         }
       });


just after your call to super()

It seems far as far as it goes. Now what?
0
 

Author Comment

by:sara_uk
ID: 8000976
i know that step will close my window,but i didn't meant that..i wish to know how to store the data in database using hashtable class?

any answer i appreciated
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8001018
Not quite sure what you're getting at. A hashtable is a way of storing things in memory and is not persistent. A database implements persistence.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sara_uk
ID: 8001060
okay then,how do i create a class for hashtable in server program and what will include?because in my program i wish to store the book,isbn and author..when i press the button it will get the values of that key,like quantity and price....

now i wish to know what is the next step in my program?i other word,what suppose i do now?

thanks alot
0
 

Author Comment

by:sara_uk
ID: 8001068
okay then,how do i create a class for hashtable in server program and what will include?because in my program i wish to store the book,isbn and author..when i press the button it will get the values of that key,like quantity and price....

now i wish to know what is the next step in my program?i other word,what suppose i do now?

thanks alot
0
 
LVL 3

Assisted Solution

by:NetWize
NetWize earned 100 total points
ID: 8002390
Ok, so your key = (title, isbn, author) and you always have all of them when accessing your Hashtable-Database?

//This ist your "database"
protected Hashtable database = new Hashtable();

I suggest you create two classes for holding your key and value data:

public class Key {
  public String title;
  public String isbn;
  public String author;
  public boolean equals(Object o) {
    if(o instanceof Key) {
      Key k = (Key)o;
      return k.title == title &&
           k.isbn == isbn &&
           k.author == author;
    } else {
      return false;
    }
  }
  public int hashCode() {
    return ("Key"+title+"#"+author+"#"+isbn).hashCode();
  }
}

public class Value {
  public int quantity;
  public double price;
}

Now you can enter Key/Value-Pairs into your database:
Key k = new Key();
k.title = "Programming in Java";
k.isbn="1.2.3.4";
k.author="Myself";

Value v = new Value();
v.quantity = 0;
v.price = 0.0;

database.put(k, v);

//Searching for an entry:
Key k = new Key();
k.title = "Programming in Java";
k.isbn="1.2.3.4";
k.author="Myself";
if(database.containsKey(k)) {
  Value v = (Value)database.get(k);
  System.out.println("Quantity: " + v.quantity);
}

Of course you'd better use getters and setters for your key/value classes along with some specialized constructors...

I hope this is what you ment ;-)

Jan
0
 

Author Comment

by:sara_uk
ID: 8002528
hi again..
first of all,iam very much thanks to you.further more,you didn't mentioned which library i will choose for that ,finally,do i need to put or implement these codes in my server program..


iam really much appreciated for assistant..
0
 

Author Comment

by:sara_uk
ID: 8002557
hi again..
first of all,iam very much thanks to you.further more,you didn't mentioned which library i will choose for that ,finally,do i need to put or implement these codes in my server program..


iam really much appreciated for assistant..
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8003198
First of all, before you do *anything* else, you should have a Book class. Then you should decide what to do next. What do you mean by 'store'? In memory? In the file system?

NetWize - the hashCode of the Book's isbn (after having been stripped of non-alpha-numeric symbols) should be sufficient for a Book's key.
0
 

Author Comment

by:sara_uk
ID: 8004572
iam sorry guys...i didn't understand anything from your comments,i mean where i need to put those codes and to implement them in server program...if u didn't understand yet then tell me what i will do next?

thanks alot and appreciated..
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8004721

Don't worry too much about comments getting passed around between experts. You understand this i hope?:

>>First of all, before you do *anything* else, you should have a Book class.
0
 

Author Comment

by:sara_uk
ID: 8005012
ok then...how do i create that book class with codes and where to locate it?if you help me please and provide me with example,i appreciate that..

thanks
sara
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8005099
You need to study basic OOP with Java. Try http://sepwww.stanford.edu/sep/josman/oop/oop1.htm
0
 

Author Comment

by:sara_uk
ID: 8015726
hi dear NetWize:
in the above example you written isbn=string,in this case it's int.

if you please rephrase those codes and write them in proper way that will help me to add them in java for testing purpose?

i appreciate your answer..
thanks
0
 
LVL 3

Expert Comment

by:NetWize
ID: 8015811
replace public String isbn;
with

public int isbn

// and change the hashCode-method to

public int hashCode() {
  return isbn;
}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8015951
isbns can contain character data as well as digits AFAIK.
0
 
LVL 3

Expert Comment

by:NetWize
ID: 8016178
Yes, CEHJ, that's right. But if sara_uk's isbn is int...
0
 

Author Comment

by:sara_uk
ID: 8016223
thanks alot experts...

finally,if you please submit my example above plus yours and conclude it for me,i mean can you relate all what i did above with your code and give me the final codes..
i hope you understand what i mean..

iam very much thanks to experts like you dear...

thanks alot
 
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8016289
Over to you NetWize - i don't do homework for people - only assist ;-)
0
 
LVL 3

Expert Comment

by:NetWize
ID: 8016306
Well sara_uk,
I think you're asking too much. This is not about coding someone elses programs but helping you do it yourself. If we'd write your code what benefit would you have? Next time you won't be able to do it yourself again.

You really should invest some time in learning the language.

Sorry I can't help you.

Jan
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8016408
I suggest that if you don't know how to write a Book class you follow the link i posted. You won't get people to write your homework here.
0
 

Expert Comment

by:CleanupPing
ID: 9059143
sara_uk:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question