Home Answers Viewqa Java-Beginners Java Servlet - matching 2 databases

 
 


Karen
Java Servlet - matching 2 databases
2 Answer(s)      3 years ago
Posted in : Java Beginners

Dear Experts,

I have 2 tables in a database, parents and memberparticulars resepectively.
parents is the table that contains parents data.
memberparticulars is the table that contains tutors data.

I'm trying to match parents' who has indicated subjects wanted, qualifications wanted from tutors to tutors who can teach that subjects and have the relevant qualifications.

My aim is to display the tutors' names, ID, contact number that fit the above criteria.


Hence, I created a separte servlet to do that.

But, I'm not sure if I need to join tables or not?

So, I use:

public class processMatch extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, ClassNotFoundException, SQLException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
Connection con = null;
ResultSet rs = null;
PreparedStatement ps = null;
Statement stmt = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/tangara_member", "tangara_karen", "csw9l?xPJpXA");

String query = "SELECT FROM memberparticulars, parents WHERE memberparticulars.strSubjectsME = parents.strSubjects" && memberparticulars = "Degree holder";

ResultSet resultSet = stmt.executeQuery(query);
response.setContentType("text/xml");
out.write("<html><body><H3>Display list of tutors which match Parents' subjects and levels requested</H3>");
out.write("<tr><td>Name</td></tr>");
out.write("<tr><td>Contact</td></tr>");
out.write("<tr><td>Subjects</td></tr>");
int i = 0;
while (resultSet.next()) {
i++;
out.write(resultSet.getString("strFullNameME"));
out.write(resultSet.getString("strContactME"));
out.write(resultSet.getString("strSubjectsME" + " "));
}
out.write("</body></html>");
con.close();
} catch (ClassNotFoundException cnfe) {
System.err.println("Error loading driver: " + cnfe);
} catch (SQLException sqle) {
System.err.println("Error with connection: " + sqle);
} finally {
out.close();
}}}

Please advise my query is correct or not?

Many thanks.


View Answers

June 7, 2010 at 11:55 AM


Hi Friend,

Use the following query:

"SELECT * FROM parents,memberparticulars WHERE parents.subjects = memberparticulars.subjects and parents.qualification = memberparticulars.degree";

In the table 'parents', we have taken id, subjects and qualification as fields and in 'memberparticulars', we have taken id, name, contact, subjects, degree as fields.

Hope that it will be helpful for you.
Thanks

July 21, 2010 at 10:51 AM


Dear experts,

So happy I get through this ask a question page again. Thank God.

I want to say "A BIG THANK YOU" for helping me about the matching codes.

It is working now after fine tuning the SQL query :-) but I can't do it without you showing me the steps.

My question is that the table display the 100% match.
[parents request = UPMATH LPMATH, tutor = UPMATH LPMATH]

What if I want to have 80% match also included, how do I do it?

If the parents ask for subjects to be tutored are UPMATH LPMATH and the tutors can teach UPMATH LPMATH LPENG.

I would like to include that tutor as well.

How do I change my query in order for that tutor's particulars to be displayed as well?

Looking forward to your guidance. Many thanks.










Related Pages:
databases
databases  i want to know the method of the servlet class in which i should write the code for initializing the database connection together with an example of a code for initializing the database connection
databases
databases  i want to know the method of the servlet class in which i should write the code for initializing the database connection together with an example of a code for initializing the database connection
databases
databases  i want to know the method of the servlet class in which i should write the code for initializing the database connection together with an example of a code for initializing the database connection
databases
databases  i want to know the method of the servlet class in which i should write the code for initializing the database connection together with an example of a code for initializing the database connection
databases
databases  i want to know the method of the servlet class in which i should write the code for initializing the database connection together with an example of a code for initializing the database connection
Databases
; 2)insertdata.jsp: <%@page import="java.sql.*"%> <% String name
java code to validate column content of 2 different tables in 2 different databases.
java code to validate column content of 2 different tables in 2 different databases.  Database have been migrated from old to new one as per.... how to compare 2 columns(different col_name) in 2 different databases placed
connecting databases
connecting databases  I need to connect mysql on 2 or more remote pc'c. how can i giv the ip address for 2 or more systems. is it possible to connect to the required systems by user specifying the database and table name my
About MVC 2 architecture and jsp - JSP-Servlet
in java.As Servlet contains the pure java code and coding is needed to generate...About MVC 2 architecture and jsp  Sir, I want to know about MVC 2... to use the tags with java language. It is basically used for presentation
codes for banking databases
codes for banking databases  sir plz give me codes for creating a banking database using java
codes for banking databases
codes for banking databases  sir PLZ give me codes for banking database using java
codes for banking databases
codes for banking databases  sir plz give me codes for creating a banking database using netbeans as back end and java as front end
Biological Databases Links
Biological Databases       Biological Databases are like any other databases... databases: Biological Database Links
Struts 2 Training
. The basic platform requirements are Servlet API 2.4, JSP API 2.0 and Java 5... Struts 2 Training       The Struts 2 Training for developing enterprise applications with Struts 2 framework. Course
need help....how to connect and disconnect multiple databases(databases created in mysql) using java and my sql
need help....how to connect and disconnect multiple databases(databases created in mysql) using java and my sql  i am working on a project on deadlock in distributed transactions , and in that i am using my sql in java i need
Java : Servlet Tutorials - Page 2
Java : Servlet Tutorials       Context attributes in Servlet All Servlets... to a servlet.   Quick Introduction to Java Servlets
Java Captcha in Struts 2 Application
Java Captcha in Struts 2 Application       This Java Captcha Example demonstrates you how to develop a captcha Servlet and use in your Struts 2 application. Developing Struts 2 Captcha
Introduction to Struts 2 Framework
, Java Beans, ResourceBundles, XML etc. Struts 2 Framework is very...Introduction to Struts 2 Framework - Video tutorial of Struts 2 In this video... of the Struts 2 Framework. The Struts 2 framework is very elegant framework
Servlet
the same error <web-app> <servlet> <servlet-name>InsertServlet</servlet-name> <servlet-class>InsertServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>
new 2
new 2  <%@page import="java.util.ArrayList"%> <%@page...; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2 sevelet @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2 import java.io.IOException; import
Struts 2
Struts 2  I am getting the following error.pls help me out. The Struts dispatcher cannot be found. This is usually caused by using Struts tags... passed through its servlet filter, which initializes the Struts dispatcher needed
Introduction to Struts 2
, JSP API 2.0 and Java 5.  Video Tutorial - Introduction to Struts 2...Introduction to Struts 2       This section provides you a quick introduction to Struts 2 framework
Struts 2 Guide
Struts 2 Guide       This is first example of Struts 2 in this Complete application development tutorial series. You must finish this Struts 2 Guide in day 1 itself. Struts is vast topic
Struts 2 Tutorial
Struts 2 Tutorial       RoseIndia Struts 2 Tutorial and Online free training helps you learn new elegant Struts 2 Framework with examples. Struts 2 is very elegant and flexible front
Servlet Interview Questions - Page 2
Servlet Interview Questions - Page 2   ... method. Initialization is covered in Initializing a Servlet. 2. The container... of Servlet? Answer: The interface javax.servlet.Servlet,  defines the three life
Struts 2 Features
platform requirements are Servlet API 2.4, JSP API 2.0 and Java 5.  Some of the general features of the current Apache Strut 2 framework are given below. ... Struts 2 Features       The strut-2
Echo 2
Echo 2       Echo 2 allows you to code Ajax apps in pure Java (Demo)which automatically generates HTML and Javascript. Read full Description
java code 1 of 2
java code 1 of 2  Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes   Hi Friend, Visit
Switch databases
Switch databases  How do you inter-change between relational databases without code changes
Moire Pattern 2 Java
Moire Pattern 2 Java   textWhat you are seeing in the screenshot...; g2.setColor(Color.black);g2.fillOval(centerX, centerY - ovalWidth / 2, 300, ovalWidth... - ovalWidth / 2, 300, ovalWidth);g2.rotate(Math.toRadians(15),centerX,centerY
task 2 - Java Beginners
task 2  Write a time server that follows the time protocol outlined in RFC 868. When a client connects, the server sends a 4-byte, big-endian, unsigned integer specifying the number of seconds that have passed since 12:00 A.M.
java code 1 of 2
java code 1 of 2  Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes   Hi Friend, Try
java servlet programming - JSP-Servlet
java servlet programming  i want 2 insert the date time into the sql column of data type datetime through servlets dynamically .How 2 do dat
GUI 2 - Java Beginners
GUI 2  How can I modify this code? Please give me a GUI... world and like it alot. I was wondering where can I go to learn more about java and C++.  Hi You need not worry of where to go and learn about java
Java 2 micro editionJ
Java 2 micro editionJ  Hello, i am using JCreator, for writing my J2ME program, after building the program, it keeps on given me the following errors: package javax.microedition.midlet does not exist package
que 2 - Java Beginners
que 2  WAP to input a string & print out the text withthe uppercase & lowercase letters reversed,but all other characters should remain the same. eg: input:WelComE TO School output:wELcOMe to sCHOOL  Hi Friend
Struts 2 Architecture - Detail information on Struts 2 Architecture
Struts 2 Architecture       Struts and webwork has joined together to develop the Struts 2 Framework. Struts 2 Framework... of Struts 2 Framework. Request Lifecycle in Struts 2 applications User Sends request
Web 2
be accessed in various forms like an HTML page, Javascript, Flash, Silverlight or Java
Java Loop 2 - Java Beginners
Java Loop 2  WAP to print d following patter wid d help of ne loop possible
Detailed introduction to Struts 2 Architecture
Detailed introduction to Struts 2 Architecture       Struts 2 Framework Architecture In the previous section we learned... components of Struts 2 framework. How Struts 2 Framework works? Suppose you
Java: String Exercise 2
Java: String Exercise 2 Name ______________________ Assume the following..., or illegal. 1__________h.length() 2__________h.substring(1) 3__________h.toUpperCase...("c") 19__________"a".compareTo("A") 20__________s.trim().charAt(2) String
problem in inserting data in databases created in netbeans using jsp..
problem in inserting data in databases created in netbeans using jsp..  i am trying to make a virtual classroom website in jsp using netbeans.i...; </form> </html> 2)insert.jsp: <%@page import="java.sql.
Struts 2 - History of Struts 2
Struts 2 History       Apache Struts is an open-source framework that is used for developing Java web application. Originally... an excellent framework for developing application easily by organizing JSP and Servlet
2's Complement
2's Complement  hi Can anyone plsss tell me the 2's complement java program... Thanks in advance
OOP with Java 2 - Java Beginners
OOP with Java 2  Define a class called BogEntry that could be used to store an entry for a Web log. The class should have member variables to store the poster's username, text of entry, and the date of the entry using the Date
Java 2 SDK, Standard Edition,
Java 2 SDK, Standard Edition,  Once I have the Java 2 SDK, Standard Edition, from Sun, what else do I need to connect to a database
Struts 2 Hello World Application Example, Learn how to develop Hello World application in struts 2.
Struts 2 Hello World - Developing Hello World Application...; In this section we will develop Hello World application based on Struts 2 Framework. Our Struts 2 Hello World application is your first step towards
Open Source Databases
Open Source Databases The Open Source Database Benchmark Featuring... Source Databases: A brief look This month I take a brief look at Open Source... databases? Most readers have probably heard of MySQL. Its byline is The World's most

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.