473,397 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Compare Two DataBase

Hello fellow Experts,

i have two database with the following tables
customers and scrub.

customers table has folowing:
id customers
Phone
First Name
Last name
Address
City
State
Zipcode
Email
Investment
Source
Assign
Statue
CustomerNotes

Scrub has the following
idscrub
First
Last

What i am trying to do is compare the scrub Database with the customer Database and find all the matchs to delete them out of customer database.

So far my code work for first record in customer them stops. I been changed code and still get the same results.

if there an easier way please let me know.

i have 3355 names to take out of the 77005 customer database.

I working with jsp and mysql.

Thanks for your time,

CT
Expand|Select|Wrap|Line Numbers
  1. <%@ page import="java.sql.*"%>
  2. <%@ page import="javax.servlet.*"%>
  3.  
  4.  
  5. <%
  6. String connectionURL = "jdbc:mysql://localhost:3306/bjc?user=;password=";
  7. Connection connection = null;
  8. Connection Mconnection = null;
  9. Statement statement = null;
  10. Statement Mstatement = null;
  11. ResultSet rs = null;
  12. ResultSet Mrs = null;
  13.  
  14.  
  15. Class.forName("com.mysql.jdbc.Driver").newInstance();
  16. Mconnection = DriverManager.getConnection(connectionURL, "root", "password");
  17. connection = DriverManager.getConnection(connectionURL, "root", "password");
  18. Mstatement = Mconnection.createStatement();
  19. statement = connection.createStatement();
  20. Mrs = Mstatement.executeQuery("SELECT * FROM scrub");
  21. rs = rs = statement.executeQuery("SELECT * FROM customers");
  22.  
  23. String holder1 = null;
  24. String holder1a = null;
  25. String holder2 = null;
  26. String holder2a = null;
  27. int idholder = 0;
  28. int temp = 0;
  29.  
  30. while (rs.next()){
  31.     idholder = rs.getInt("idcustomer");
  32.  
  33.  while (Mrs.next()){
  34.      holder1 = Mrs.getString("last");
  35.      holder2 = rs.getString("Last Name");
  36.      holder1a = Mrs.getString("First");
  37.      holder2a = rs.getString("First Name");
  38.  
  39.      out.println(idholder);
  40.      out.println(" ");
  41.      out.println(temp);
  42.      out.println(" ");
  43.      out.println(holder1a);
  44.      out.println(" ");
  45.      out.println(holder1);
  46.      out.println(" ");
  47.      out.println(holder2a);
  48.      out.println(" ");
  49.      out.println(holder2);
  50.      out.println("<br>");
  51.  
  52.  
  53.      if (holder2.equalsIgnoreCase(holder1) && holder2a.equalsIgnoreCase(holder2)){
  54.          out.println("row "+idholder+" "+holder2a+" "+holder2+"\n");
  55.      } 
  56.      } temp++;  
  57. }
  58.  
  59.  
  60.  
  61.  
  62. rs.close();
  63. statement.close();
  64. connection.close();
  65.  
  66.  
  67. %>
  68.  
Jan 25 '12 #1

✓ answered by ComputerTechie

I cam up with the following solution.


Expand|Select|Wrap|Line Numbers
  1. SELECT customers.`First Name`,customers.`Last Name`,customers.idcustomer,scrub.idscrub,scrub.`First`,scrub.Last
  2. FROM customers ,scrub
  3. WHERE customers.`First Name` = scrub.`First` AND customers.`Last Name` = scrub.Last
  4. ORDER BY customers.idcustomer  
  5.  
  6.  
  7.  
  8. DELETE FROM customers c
  9. WHERE EXISTS (SELECT 'X' FROM scrub
  10. WHERE c.`First Name` = scrub.`First` AND c.`Last Name` = scrub.Last
  11. ORDER BY c.idcustomer )

7 6850
C CSR
144 100+
Why does it look like you're comparing holder2a to holder2? Shouldn't it be holder2 = holder1, holder2a = holder1a?
Jan 25 '12 #2
Sorry i did post the older code here is new line

Expand|Select|Wrap|Line Numbers
  1. if (holder2.equalsIgnoreCase(holder1) && holder2a.equalsIgnoreCase(holder1a))
  2.  
as for the compare you can not as for are i know use = and have to use .equals

Expand|Select|Wrap|Line Numbers
  1. if (holder2.equalsIgnoreCase(holder1) && holder2a.equalsIgnoreCase(holder2)){
CT
Jan 25 '12 #3
C CSR
144 100+
I used "=" just as shorthand. If the New code still isn't working I'm out of my league on this. I was just looking at random questions and I noticed the 2a = 2 discrepancy. Hang in there:)
Jan 25 '12 #4
lgm001
9
God you people make your lives difficult...

Reads your mySql manual...

Using SQL outer joins will yield the differences.

SELECT * FROM customer LEFT JOIN scrub
-> ON customer.firstname = scrub.firstname
-> AND customer.lastname = scrub.last
-> WHERE customer.firstname IS NULL;

Basically this says give me all the records that are in scrub and match them with customer... Make an empty customer.name field if there isn't a match in the customer... All you will get from this select is whats left in scrub.
Jan 25 '12 #5
lgm001,

You need to test what you wrote. it does not work but i did come up with a solustion that i will post. soon.

CT
Jan 26 '12 #6
lgm001
9
Well... post a dataset to work with then...
Jan 26 '12 #7
I cam up with the following solution.


Expand|Select|Wrap|Line Numbers
  1. SELECT customers.`First Name`,customers.`Last Name`,customers.idcustomer,scrub.idscrub,scrub.`First`,scrub.Last
  2. FROM customers ,scrub
  3. WHERE customers.`First Name` = scrub.`First` AND customers.`Last Name` = scrub.Last
  4. ORDER BY customers.idcustomer  
  5.  
  6.  
  7.  
  8. DELETE FROM customers c
  9. WHERE EXISTS (SELECT 'X' FROM scrub
  10. WHERE c.`First Name` = scrub.`First` AND c.`Last Name` = scrub.Last
  11. ORDER BY c.idcustomer )
Jan 27 '12 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Evgeny Gopengauz | last post by:
Let us suppose that I have two similar databases and need to create an sql-script upgrating one database structure to another. For example, these databases are from different versions of some...
0
by: DBCompare | last post by:
A couple of weeks ago we released xSQL SDK v2.0 Beta that allows you to compare the schemas of 2 SQL Server databases as well as generate synch scripts with just a few lines of code. We think it's...
0
by: Mark | last post by:
All, Excuse the re-post but I have found something which works for the UserID but not for the Password (see previous post below). The problem is I don't understand how it works and therefore...
2
by: Michael König | last post by:
Hello, I'm developping a new application (btw: I'm not a real specialist but more or less a newbie). Now I have the following problem: Each time I leave the main form of the application Access...
0
by: gm | last post by:
Immediately after generating the Access application from the Source Safe project I get: "-2147467259 Could not use ''; file already in use." If Access database closed and then reopened I get:...
12
by: John Baker | last post by:
Hi: I have read a number of threads on the issue of compressing (compacting) Access data bases programmatically, and have been left confused. We are using Access 2000, and I need code that will...
11
by: John Ortt | last post by:
Hi everyone. I have a database which I have developed in Access 2000 which is working nicely. The problem is that my customer only has Access 97. I tried to convert the database but the main...
3
by: John Phelan-Cummings | last post by:
I have a front-end application called, “inbusiness.mdb” and three back-ends databases called, “inbusinessClient_be.mdb”, “inbusinessFund_be.mdb”, and, “inbusiness_be”. I created three back-ends...
21
by: Kristaps | last post by:
Hi everyone! I have some questions, maybe someone can help me... I write script for table comparing, but it works wery slovly. There is the script, can anyone give some tip how can I make this...
0
by: Lysander | last post by:
I'm sure many of you use backend and frontend databases. The backend holds all the tables, the frontend holds all the code. If you are developing for a multi-user system, you may have the same...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.