• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

database in server?important please

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
sara_uk
Asked:
sara_uk
  • 9
  • 8
  • 4
  • +1
2 Solutions
 
CEHJCommented:
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
 
sara_ukAuthor Commented:
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
 
CEHJCommented:
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
Independent Software Vendors: 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!

 
sara_ukAuthor Commented:
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
 
sara_ukAuthor Commented:
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
 
NetWizeCommented:
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
 
sara_ukAuthor Commented:
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
 
sara_ukAuthor Commented:
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
 
CEHJCommented:
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
 
sara_ukAuthor Commented:
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
 
CEHJCommented:

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
 
sara_ukAuthor Commented:
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
 
CEHJCommented:
You need to study basic OOP with Java. Try http://sepwww.stanford.edu/sep/josman/oop/oop1.htm
0
 
sara_ukAuthor Commented:
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
 
NetWizeCommented:
replace public String isbn;
with

public int isbn

// and change the hashCode-method to

public int hashCode() {
  return isbn;
}
0
 
CEHJCommented:
isbns can contain character data as well as digits AFAIK.
0
 
NetWizeCommented:
Yes, CEHJ, that's right. But if sara_uk's isbn is int...
0
 
sara_ukAuthor Commented:
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
 
CEHJCommented:
Over to you NetWize - i don't do homework for people - only assist ;-)
0
 
NetWizeCommented:
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
 
CEHJCommented:
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
 
CleanupPingCommented:
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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 9
  • 8
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now