• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mysql Databse and jsp

 
walter bakshi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two table one is question table and another is option table both are connected so question id is the foreign key
in another option table which is referring all possible option. i want to retrieve the question with its all option like multiple choice
which we generally find over net and user can set the number of option so option can have any number(basic idea about the task)
so i need help in query to retrieve these things and UI code also...please reply me on this.
 
K. Tsang
Bartender
Posts: 3583
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you planning to use a single query to retrieve all q&a ... forget it. It may be wrong and joining will simply make things error prone.

I suggest retrieving questions and answers separately and use a Map to store such pairing. Each question has a list of answers.

In fact, I personally use such approach in one of my apps and it works great.
 
walter bakshi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you sir, i got one query regarding that in that it is saving same option with one question and now i have to print those
option with particular question so i will try that by tomorrow and please sir can you give me an example that which you are trying
with considering some table name and column and list and all also because i am new to this thing please sir help me..
 
K. Tsang
Bartender
Posts: 3583
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To start you need 2 classes: 1) Questions and 2) Answers.

Then in your logic set up a Map<Question, List<Answer>> meaning a map of question keys, each with a list of answers.

The fetch data and populate the map.



That should get you started. The trick is if the question has no answers, a empty list should be in place.
 
walter bakshi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

thank you sir, actually i was not using hibernate first i was trying with simple java class in which one is related to storing
question into question table and another for inserting option and i think you are using hibernate so i am bit confused
i am using simple servlet under one package and package having total three classes one is for connection with databse
and other two storing question and option but i am not using any object concept here so you tell me you are telling through
hibernate?
 
K. Tsang
Bartender
Posts: 3583
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope not using Hibernate. The Question and Answer classes are simple POJO that should represent your DB structure.

 
walter bakshi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you sir, you are helping me a lot sir i was using servlet no java.lang.pojo class and all. so i will go with java.lang.pojo class
i know about java.lang.pojo class but not so much and i do not have idea how it connects to database and storage all
so please if you help me to provide me some link or some small code for java.lang.pojo class with database that will be helpful for me
so provide me if you can thanks a lot sir.
 
K. Tsang
Bartender
Posts: 3583
16
Android Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no class called java.lang.pojo in java. A POJO stands for "plain old java object". This means you create a class say call Question in your case and this class is a POJO. Same thing goes for Answer.

Once such class exists, you can use it to store the questions or answers then populate the Map data structure I shown before.

The concept of POJO can be applied to core java and enterprise jave (servlet, ejb etc).
 
walter bakshi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you sir, yeah sir i know there is no such type word actually it was because of rule are so complex here how to write and all. so
i will have one java server page in that one form will be there where i will get the question values and all and in action of form i will
give the question class name right? but how it will reach to database without using servlet that much i do not know so i asked you for
the link or some code in which it is setting and getting the values and saving it into database because i was using that was different
in that i was saving through servlet using result set and prepare statement and all so please tell me how it will save to database using
pojo class
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"souravvvv gupta", please check your purple mooseages for an important administrative matter. Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic