Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting selected contents from database table

 
ankita balaji
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody,
Good Morning.I have a small doubt regarding my project.I request you kindly to solve my problem.
Now my project is to create a questionnaire with servlets as frontend,JDBC as middleware n Mysql as backend.
Suppose that there are several options(it will b fair,if we call them as links) for a user to have a online test say

1.Java section
2.JSP section.
3.Servlets section.etc

Now,in my database table,I have several number of questions all mixed of servlets,java,jsp,mysql etc.My database table for these questions looks as:

SecdescriptionQuestion AnswerAAnswerBAnswerCAnswerD
JavaWat is java?LanguagePackageDatabaseNone
ServletsWat is a servlet?LanguagePackageDatabase
JSpWat is jsp?LanguagePackageDatabaseNone

JavaIs java portable?YesNoCant SayNone
������������.

Now my doubt is that if a user clicks on anyone of the links(java/servlets/jsp) it should link to one common page and the database has to fetch all the questions related to the section they clicked and print the questions on the servlet page i.e if the user clicks on java,he has to get java questionnaire,if the user clicks on JSP he has to get JSP questions and so on


Hope anyone help me in this aspect.
Expecting a solution from you,
yours thankfully.
Ankita.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can have a hidden field in your form page. say

<input type="hidden" name = "id" value="">

onClick call the function say, getQuestions(). set id to "jsp" or "java" inside the getQuestion() and submit the form to servlet.

on server side use

String id = request.getParameter("id")

then query the database

String query = "select * from questions where secDescription = ?"
pstmt.setString(1, id);
executeQuery();
 
Jyothi Lature
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ankita,

The solution would be something like this:

When you click on any one of these links (Java, JSP, Servlet), call another servlet say, Questionnaire.java which would fetch a parameter as either java or jsp or servlet and then run a SQL query to get all the questions related to the section they clicked and then print the questions on the servlet page.
To do this follow these steps:
Step 1: Your link shouls have the code like this:
<a href="Questionnaire.java?qType=Java">Java</a>
<a href="Questionnaire.java?qType=JSP">JSP</a>
<a href="Questionnaire.java?qType=servlet">Servlets</a>

Step 2:Fetch parameter in your Questionnaire servlet as:

String qn_type = request.getParamater("qType");

Step 3: Your SQL query to get all the questions related to the section would be:

"SELECT DECSRIPTION, QUESTION, ANSWERA, ANSWERB, ANSWERC,...
FROM MYTABLE
WHERE SEC='"+qn_type"'";

Step 4: Print the results in the format you want using out.println statements.

So, in thsi way you are having just one comman program being called i.e., Questionnaire.java in the above case..

Hope this solution is helpful.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic