Hello friends,
i need java source code for cross matching two large access database records (1st file is of 20000records {28 columns and 20000 rows} and 2nd file is of 39000records {30 columns and 39000 rows}).I need to compare each n every cell of 1st file to the each n every cell of 2nd file.i have written code for this but its not working for more then 20 records only, whenever i am trying to crossmatch more then 20 records, my netbean IDE stuck nd my PC restarts. my desired output should be tht record tht has same cell.
plz help
thanks in advance.

Recommended Answers

All 16 Replies

Let's see your code (in code tags, please).

ya sure
its in my office desktop.
i will bring n post here on monday.
thanks.

by d way, can u giv me a new code for the same (if you don mind)

ya sure
its in my office desktop.
i will bring n post here on monday.
thanks.

Till Monday then

How about a table join.

SELECT * FROM Database1.TableName1 INNER JOIN Database2.TableName2 ON Table1.field1 = Table2.field1;

(Double check all this syntax, its psudo codish, and im not any kind of expert in SQL or Java)

If you want to do that in java just get a Connection then

TreeSet<String> primaryKeys = TreeSet<String>();

Statement statement = connnection.createStatement();
ResultSet results = statement.executeQuery("SELECT * FROM Database1.TableName1 INNER JOIN Database2.TableName2 ON Table1.field1 = Table2.field1")

while(results.next)
{
     primaryKeys.add(results.get(0));
}

The point is that you don't do something through java if it can done through sql which is faster. So try to provide a better explanation about what you are trying to do.

I have two database's
1st database has 21 columns and 20140 records
2nd database has 27 columns and 61603 records.
i need to compare each and every cell of 1st database to each n every cell of 2nd database and the output should be the rows where two cells are matching from both database's.

plz help me to gt java source code for tht

commented: 3 weeks, and all you can do is repeat the original question - post YOUR code, not excuses. -6

I have two database's
1st database has 21 columns and 20140 records
2nd database has 27 columns and 61603 records.
i need to compare each and every cell of 1st database to each n every cell of 2nd database and the output should be the rows where two cells are matching from both database's.

plz help me to gt java source code for tht

I have better idea, you provide coding what you done so far. Explain where you facing difficulties and somebody may try to help you.

Until then I believe there is nothing we have to discus. Prove you are worth the time we spend on your problem....

I have two database's
1st database has 21 columns and 20140 records
2nd database has 27 columns and 61603 records.
i need to compare each and every cell of 1st database to each n every cell of 2nd database and the output should be the rows where two cells are matching from both database's.

plz help me to gt java source code for tht

No one can answer that question and do you know why?
Because even if we wanted to hand you the code, which we won't, how are we supposed to compare 2 databases when we don't know the database names, hosts, ports, usernames, passwords, the table names and the column names?

Haven't you said in your previous posts the you have the code and that you will post it next Monday?
Do you know how many Mondays have past?

We would have helped you if you asked specific questions. Do you know how many examples are in this forum on how to connect to a database using java code?

My code is

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class ComparisionServlet extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		doProcess(request,response);

	}

	private void doProcess(HttpServletRequest request,
			HttpServletResponse response)throws ServletException,IOException {
		// TODO Auto-generated method stub
		
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		Connection con=null;
		PreparedStatement st1=null;
		PreparedStatement st2=null;
		ResultSet rs1=null;
		ResultSet rs2=null;
		int ccount1=0;
		int ccount2=0;
		
		try {
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			System.out.println("Driver Loaded..");
			con=DriverManager.getConnection("jdbc:odbc:comparision");
			System.out.println("Connection Established..");
			
			st1=con.prepareStatement("select * from Student1");
			System.out.println("Student1 Statement created..");
			
			st2=con.prepareStatement("select * from Student2",ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			System.out.println("Student2 Statement created..");
			
			rs1=st1.executeQuery();
			System.out.println("Student1 ResultSet created..");			
			ResultSetMetaData rsmd1=rs1.getMetaData();
			System.out.println("ResultSetMetaData ResultSet1 created..");
			ccount1=rsmd1.getColumnCount();
			System.out.println("column count1.."+ccount1);
			
			rs2=st2.executeQuery();
			System.out.println("Student2 ResultSet created..");
			ResultSetMetaData rsmd2=rs2.getMetaData();
			System.out.println("ResultSetMetaData ResultSet2 created..");
			ccount2=rsmd2.getColumnCount();
			System.out.println("column count2.."+ccount2);
			String[] record=new String[5];
			while(rs1.next()){
				System.out.println("Inside rs1.next()");
				for(int i=1;i<=ccount1;i++){
					record[i-1]=rs1.getString(i);
				}
				rs2.beforeFirst();
				while(rs2.next()){
					String[] record1=new String[5];
					System.out.println("Inside rs2.next()");
					int result=0;
					for(int i=1;i<=ccount1;i++){
						record1[i-1]=rs2.getString(i);
					}
					for(int i=0;i<record1.length;i++){					
						if((record[i]).equals(record1[i])){
							System.out.println("Inside if condition");
							result++;
						}
					}
					if(result>=1){
						System.out.println("Inside reuslt>=2");
						for(int i=0;i<ccount1;i++){
							out.print(record[i]+"--");
						}
						out.print("==========");
						for(int j=0;j<ccount2;j++){
							out.print(record1[j]+"--");
						}
						out.println("<br>");
					}
				}//rs2
			}//rs1
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			System.out.println(e.getMessage());
			e.printStackTrace();
		} catch (SQLException e) {
			System.out.println(e.getMessage());
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			doProcess(request,response);
	}

}

sorry frnds i know m very late.
can u help me to improve this code to wrk more fast.
and i don need to crossmatch all columns of 1st table to all columns of another table but instead i need only one column of 1st table to crossmatch with all d columns of another table.


thanks in advance

You don't run 2 queries; as proposed in previous posts you run ONE query where you make the comparisons with sql and return only the data you want.
Then you put the results in a List and send that List to a JSP where you display the data.
It is very bad idea to display data inside servlets.
Read the tutorial about MVC that is at the top of the JSP forum.

hey!! i do not have d code but do plz forward me the code by 3rd August if u get...its very urgent

hey!! i do not have d code but do plz forward me the code by 3rd August if u get...its very urgent

Here is "d code"

PS: We work at our own convenience and your urgency doesn't mean nothing to us. Sorry...

And most important: START your own thread. What you posted has nothing to do with with thread. You didn't specify your problem. Even if we wanted to help what code are we suppose to "sent"?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.