Karen
Java Servlet - matching 2 databases
2 Answer(s)      4 years and 10 months 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.


Advertisement
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
Databases
; 2)insertdata.jsp: <%@page import="java.sql.*"%> <% String name
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
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
Switch databases
Switch databases  How do you inter-change between relational databases without code changes
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
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
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 Loop 2 - Java Beginners
Java Loop 2  WAP to print d following patter wid d help of ne loop possible
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
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
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 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
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
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
Databases supported by Jdeveloper?
Databases supported by Jdeveloper?  I want to know what databases are supported by jdeveloper ?and any light database for jdeveloper
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