File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC 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
Bookmark "Getting selected contents from database table" Watch "Getting selected contents from database table" New topic
Author

Getting selected contents from database table

ankita balaji
Greenhorn

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.
Ankita.
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);
executeQuery();
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, 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.


Jyothi<br />Sun Certified Java Programmer<br />Brainbench Certified for Javascript
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting selected contents from database table
 
Similar Threads
doubt in a query
a doubt
Doubt in JSP
Web Application
How to access a webpage from a database table