Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

Have Programming Question? Ask it here!
 
 
 


Karen
Java Servlet - matching 2 databases
2 Answer(s)      4 years and a month 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
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
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
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
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
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
Java: Method Exercises 2
Java: Method Exercises 2 Name: _________________________________ What... 2... era started in ", 1970); n = add(3, 2); output("The sum is ", n
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
Databases supported by Jdeveloper?
Databases supported by Jdeveloper?  I want to know what databases are supported by jdeveloper ?and any light database for jdeveloper
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
Accessing Databases Using Java and JDBC
Accessing Database using Java and JDBC       Accessing Database using Java and JDBC Database plays... develop and example to access the database using Java and JDBC. For this, firstly
Java Programming: Chapter 2 Quiz
Quiz Questions For Chapter 2 THIS PAGE CONTAINS A SAMPLE quiz on material from Chapter 2 of this on-line Java textbook. You should be able.... Question 2: What does the computer do when it executes a variable
Java: Programming: Initials 2 - Answer
Java: Programming: Initials 2 - Answer 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23...(blankPos+1, blankPos+2); } //.. Convert to upper case
Java Programming: Chapter 2 Index
-scale structure. Contents of Chapter 2: Section 1: The Basic Java... Chapter 2 Programming in the Small I Names and Things... and decisions. In a high-level language such as Java, you get to work
Java Programming: Chapter 2 Exercises
Programming Exercises For Chapter 2 THIS PAGE CONTAINS programming exercises based on material from Chapter 2 of this on-line Java textbook... of the integers 1, 2, 3, 4, 5, or 6 at random. The number you pick represents the number
WAP in java to print the series 1*2*3
WAP in java to print the series 1*2*3  WAP in java to print the series 123
java 2 - Java Server Faces Questions
java 2  1) a) Write a pseudo code algorithm to pick the 1st element as a pivot and a partitioning array according to the instructions given... and partitioning) to Java. It should be able to execute any set of data. Note:- You should
mysqldump all databases
mysqldump all databases  How to take the backup of complete data including all the databases in the MySQL Server? Is there one command to take...-databases > all_databases.sql Thanks
java bits 2 - Java Interview Questions
java bits 2  Which two classes correctly implement both the java.lang.Runnable and the java.lang.Clonable interfaces? (Choose two.) A. public class Session implements Runnable, Clonable { public void run(); public Object
Java servlet
Java servlet  What is servlet
how to compare 2 arrays using java?
how to compare 2 arrays using java?  hi can anyone give me the information regarding comparision of arrays.   Java Compare Arrays
adding of 2 bite's - Java Interview Questions
adding of 2 bite's  Java Adding of 2 bite's  this through compilation failedhere a+b returns an integer .and u try to assign an integer value to byte.(i.e. narrowing or downcasting)In case of narrowing u have
Java Struts 2 Programmer
Java Struts 2 Programmer       Position Vacant: Java Struts 2 Programmer  Job... ID: Java Struts 2 Programmer
concatinate 2 strings - Java Interview Questions
concatinate 2 strings   Write a program to concatenate two strings ?  Hi Friend, Please visit the following link: http://www.roseindia.net/java/beginners/CombinString.shtml Thanks
java (servlet) - JSP-Servlet
java (servlet)  how can i disable back button in brower while using servlet or JSP
Merge databases in SQL SErver 2005
Merge databases in SQL SErver 2005  Please help me to merge databases in SQL server 2005
Fwd: Please spend 2 minutes - Java Beginners
Fwd: Please spend 2 minutes  Fresher to Java...getting some problem with getting output for this program 1+1/2+1/3+......+1/n. please if possible send it to me   Hi Friend, Try the following code: import
 

 

 

DMCA.com