Note that there are some explanatory texts on larger screens.

plurals
  1. POinsert millions of records into two mysql tables
    primarykey
    data
    text
    <p>I have 5 tables with me each with millions of lines in each table. </p> <p>Each table has same format i.e. email, ip address, location. A single email address can be present in any of the five tables or in all of the 5 tables. And there are two other tables namely <code>User_ip</code> and <code>User_location</code>. </p> <p>I want to store unique ip adress of each email address in User_ip table, and distinct location of each email address in user_location table.</p> <p>Currently, I have been following this procedure but this is taking alot of time. Is there any other solution or method???</p> <pre><code>Statement stmt = connection.createStatement(); stmt.executeUpdate("insert into temp(email,ip,location) select email,ip,location from Apr_web group by email,ip"); stmt.executeUpdate("insert into temp(email,ip,location) select email,ip,location from Apr_gov group by email,ip"); stmt.executeUpdate("insert into temp(email,ip,location) select email,ip,location from Apr_mail group by email,ip"); stmt.executeUpdate("insert into temp(email,ip,location) select email,ip,location from Apr_pop group by email,ip"); stmt.executeUpdate("insert into temp(email,ip,location) select email,ip,location from Apr_imap group by email,ip"); stmt1 = connection.createStatement(); stmt1.executeQuery("select distinct email from temp"); ResultSet rs = stmt1.getResultSet(); while(rs.next()){ Statement stmt2 = connection.createStatement(); stmt2.executeQuery("select distinct substring_index(ip,'.',2) from temp where email='"+email+"'"); ResultSet rs2 = stmt2.getResultSet(); while(rs2.next()`enter code here`){ ip=rs2.getString(1); Statement stmt3 = connection.createStatement(); Statement stmt4 = connection.createStatement(); stmt3.executeQuery("select * from user_ip where uid='"+email+"' and ip='"+ip+"'"); ResultSet rs3 = stmt3.getResultSet(); if(rs3.next()){ System.out.println("THE ROW ALREADY EXISTS IN IP TABLE"); } else{ stmt4.executeUpdate("insert into user_ip(uid,ip) values('"+email+"','"+ip+"')"); System.out.println("ROW INSERTED IN USER_IP"); } } Statement stmt5 = connection.createStatement(); stmt5.executeQuery("select distinct location from temp where email='"+email+"' and location !='no information found'"); ResultSet rs4 = stmt5.getResultSet(); while(rs4.next()){ location = rs4.getString(1); //Statement stmt6 = connection.createStatement(); //Statement stmt7 = connection.createStatement(); pst1 = connection.prepareStatement("select * from user_location where uid=? and location=?"); pst1.setString(1, email); pst1.setString(2, location); ResultSet rs5 = pst1.executeQuery(); if(rs5.next()){ System.out.println("THE ROW ALREADY EXISTS IN USER_LOCATION"); } else{ pst2 = connection.prepareStatement("insert into user_location(uid,location) values(?,?)"); pst2.setString(1,email); pst2.setString(2,location); pst2.executeUpdate(); System.out.println("ROW INSERTED IN USER_LOCATION"); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload