1 5 6 package org.javabb.migration.betweendbs; 7 import java.sql.Connection ; 8 import java.sql.PreparedStatement ; 9 import java.sql.ResultSet ; 10 import java.sql.SQLException ; 11 import java.sql.Statement ; 12 13 public class Jbb_topics extends Jbb_Convert { 14 15 public void convert() throws ClassNotFoundException , SQLException { 16 sql = "select * from jbb_topics"; 17 18 System.out.println("TABLE JBB_TOPICS."); 19 Connection phpConn = this.getDbOrigin(); 20 Statement stm = phpConn.createStatement(); 21 System.out.println("\tReading data"); 22 ResultSet rs = stm.executeQuery(sql); 23 long i = 0; 24 25 Connection javaConn = this.getDbDest(); 26 27 javaConn.createStatement().executeUpdate("delete from jbb_topics"); 28 System.out.println("delete from jbb_topics is OK!"); 29 30 PreparedStatement ps = javaConn.prepareStatement("insert into jbb_topics (id_topic, id_user, " + 31 "id_forum, title_topic, data_topico, visualizacoes, respostas, topic_status," + 32 "topic_model, last_post_date, last_post_id, last_post_page, last_post_user_id, last_post_user_name, notify_me) " + 33 "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"); 34 35 System.out.println("\tInserting data "); 36 37 while (rs.next()) { 39 40 41 53 ps.setInt (1, rs.getInt("id_topic")); 54 ps.setInt(2, rs.getInt("id_user")); 55 ps.setInt(3, rs.getInt("id_forum")); 56 ps.setString(4, rs.getString("title_topic")); 57 ps.setTimestamp(5, rs.getTimestamp("data_topico")); 58 ps.setInt(6, rs.getInt("visualizacoes")); 59 ps.setInt(7, rs.getInt("respostas")); 60 ps.setInt(8, rs.getInt("topic_status")); 61 ps.setInt(9, rs.getInt("topic_model")); 62 ps.setTimestamp(10, rs.getTimestamp("last_post_date")); 63 ps.setInt(11, rs.getInt("last_post_id")); 64 ps.setInt(12, rs.getInt("last_post_page")); 65 ps.setInt(13, rs.getInt("last_post_user_id")); 66 ps.setString(14, rs.getString("last_post_user_name")); 67 ps.setInt(15, rs.getInt("notify_me")); 68 ps.addBatch(); 69 70 if(i%7000==0){ 71 ps.executeBatch(); 72 } 73 74 System.out.print("."); 75 } 76 System.out.println("\n"); 77 78 ps.executeBatch(); 79 ps.close(); 80 stm.close(); 81 rs.close(); 82 phpConn.close(); 83 javaConn.close(); 84 System.out.print("Done!\n\n"); 85 } 86 } 87 | Popular Tags |