File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Getting selected contents from database table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Getting selected contents from database table" Watch "Getting selected contents from database table" New topic

Getting selected contents from database table

ankita balaji

Joined: Aug 19, 2004
Posts: 11
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.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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);
Jyothi Lature
Ranch Hand

Joined: Oct 31, 2001
Posts: 60
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, 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="">Java</a>
<a href="">JSP</a>
<a href="">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:

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., in the above case..

Hope this solution is helpful.

Jyothi<br />Sun Certified Java Programmer<br />Brainbench Certified for Javascript
I agree. Here's the link:
subject: Getting selected contents from database table
It's not a secret anymore!