Java Servlet - matching 2 databases

Java Servlet - matching 2 databases

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 Tutorials/Questions & Answers:
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
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
Advertisements
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
Java : Servlet Tutorials - Page 2
Java : Servlet Tutorials     ... to a servlet.   Quick Introduction to Java Servlets... | Servlet Tutorials Page 2
Databases
; 2)insertdata.jsp: <%@page import="java.sql.*"%> <% String name
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
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 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
Maven dependency for cocoon - cocoon-databases version 2.1.9 is released. Learn to use cocoon-databases version 2.1.9 in Maven based Java projects
this version ( cocoon - cocoon-databases version 2.1.9 ) in their Java project...; cocoon - cocoon-databases version 2.1.9 java library in your project. ADS...Maven dependency for  cocoon  - Version 2.1.9 of cocoon-databases
Maven dependency for cocoon - cocoon-databases version 2.1.8 is released. Learn to use cocoon-databases version 2.1.8 in Maven based Java projects
this version ( cocoon - cocoon-databases version 2.1.8 ) in their Java project...; cocoon - cocoon-databases version 2.1.8 java library in your project. ADS...Maven dependency for  cocoon  - Version 2.1.8 of cocoon-databases
Maven dependency for cocoon - cocoon-databases version 2.1.7 is released. Learn to use cocoon-databases version 2.1.7 in Maven based Java projects
this version ( cocoon - cocoon-databases version 2.1.7 ) in their Java project...; cocoon - cocoon-databases version 2.1.7 java library in your project. ADS...Maven dependency for  cocoon  - Version 2.1.7 of cocoon-databases
Maven dependency for cocoon - cocoon-databases version 2.1.6 is released. Learn to use cocoon-databases version 2.1.6 in Maven based Java projects
this version ( cocoon - cocoon-databases version 2.1.6 ) in their Java project...; cocoon - cocoon-databases version 2.1.6 java library in your project. ADS...Maven dependency for  cocoon  - Version 2.1.6 of cocoon-databases
Maven dependency for cocoon - cocoon-databases version 2.1.5.1 is released. Learn to use cocoon-databases version 2.1.5.1 in Maven based Java projects
this version ( cocoon - cocoon-databases version 2.1.5.1 ) in their Java project... and includes  cocoon - cocoon-databases version 2.1.5.1 java library in your...Maven dependency for  cocoon  - Version 2.1.5.1 of cocoon-databases
Maven dependency for cocoon - cocoon-databases version 2.1.4 is released. Learn to use cocoon-databases version 2.1.4 in Maven based Java projects
this version ( cocoon - cocoon-databases version 2.1.4 ) in their Java project...; cocoon - cocoon-databases version 2.1.4 java library in your project. ADS...Maven dependency for  cocoon  - Version 2.1.4 of cocoon-databases
Maven dependency for cocoon - cocoon-databases version 2.1.3 is released. Learn to use cocoon-databases version 2.1.3 in Maven based Java projects
this version ( cocoon - cocoon-databases version 2.1.3 ) in their Java project...; cocoon - cocoon-databases version 2.1.3 java library in your project. ADS...Maven dependency for  cocoon  - Version 2.1.3 of cocoon-databases
java (servlet) - JSP-Servlet
java (servlet)  how can i disable back button in brower while using servlet or JSP
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
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
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
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
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.
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
Java servlet
Java servlet  What is servlet
JAVA SERVLET - JSP-Servlet
JAVA SERVLET Log   Hi, A servlet file which create the log files ,then writing values to the list & log, we should have a thousand separator and no decimal values. This means instead of writing 986300.0 in the Log file
Java(Servlet) - Servlet Interview Questions
Java Servlet examples  Java and Servlet programming examples
Switch databases
Switch databases  How do you inter-change between relational databases without code changes
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
java servlet - JSP-Servlet
java servlet  hi friends, Thanks in advance. Am poornima am created new servlet in eclipse its open but without including any code am getting..., Put servlet-api.jar into the lib folder of apache tomcat server. Thanks
java servlet
java servlet   im using ubuntu 12.04 and ialready installed eclipse but i dont know how to run the servlet programs please give brief procedure to run the servlet program in eclipse
Java servlet
Java servlet  What is the difference between an applet and a servlet
Java Servlet - JSP-Servlet
Java Servlet   Hello Sir Could you help me in understanding directory Structure for servlet page in eclipse (IDE). I save my Sevlet in WEB-INF but it is not displaying, it is displaying code of servlet. Process used
Java Loop 2 - Java Beginners
Java Loop 2  WAP to print d following patter wid d help of ne loop possible
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
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
Java 2 Micro Edition - MobileApplications
Java 2 Micro Edition  I meet difficulties to do my final project using J2me.It's about train ticket booking in mobile.Pls help on how to do this source code using j2me.Thank You
Java 2 Micro Edition - MobileApplications
Java 2 Micro Edition  I meet difficulties to do my final project using J2me.It's about train ticket booking in mobile.Pls help on how to do this source code using j2me.Thank You
executing java program with 2 classes
executing java program with 2 classes  how to run a program of java containing more than one class....ex of program is given below.... class C...); } }   Executing java program with 2 classes save the file with D.java
java 2 d array program
java 2 d array program  write a program 2-d matrix addition through...[][] A = new int[2][2]; int[][] B = new int[2][2]; int[][] C = new int[2][2...]+" "); } } System.out.println(); System.out.println("Sum of 2 matrices,Matrix C
object 2 string - Java Beginners
object 2 string  hi sir,how to convert object to string and how 2 compare object with null value to string with null value plz provide a program 4 this sir,plzzzzzzzzz
arrays part 2 - Java Beginners
arrays part 2  Question 2: Useful Array Algorithms and Operations (5 marks) Upgrade the program in Question 1 so that the program includes: ? A static method search() that: o Has a parameter of integer array and another
returning doubles with 2 decimals JAVA
returning doubles with 2 decimals JAVA  Hi all. I'm writing a program where users input the cost of an item (in the constructor), so for example, Item (string name, double cost, int qty) { ... } I have a method public double
readline Error 2 - Java Beginners
readline Error 2  Hi sir, can you look again please. The error is hard to notice, but if you execute the code, 1. enter a string the first input request (eg hello world), 2. ENTER 3a. ENTER n for the next input request
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
Databases supported by Jdeveloper?
Databases supported by Jdeveloper?  I want to know what databases are supported by jdeveloper ?and any light database for jdeveloper
Java Servlet Problem - JSP-Servlet
Java Servlet Problem  I have a servlet class that implemets the ServletContextAttributeListener interface. I am overriding all three methods, but in the attributeReplaced() method, i want to perform a redirect to another servlet

Ads