1 5 6 package org.javabb.migration.betweendbs; 7 8 import java.sql.Connection ; 9 import java.sql.PreparedStatement ; 10 import java.sql.ResultSet ; 11 import java.sql.SQLException ; 12 import java.sql.Statement ; 13 14 public class Jbb_posts extends Jbb_Convert { 15 16 public void convert() throws ClassNotFoundException , SQLException { 17 18 sql = "select * from jbb_posts "; 19 System.out.println("TABLE JBB_POSTS."); 20 Connection phpConn = this.getDbOrigin(); 21 Statement stm = phpConn.createStatement(); 22 System.out.println("\tReading data"); 23 ResultSet rs = stm.executeQuery(sql); 24 long i = 0; 25 26 Connection javaConn = this.getDbDest(); 27 28 javaConn.createStatement().executeUpdate("delete from jbb_posts"); 29 System.out.println("delete from jbb_posts is OK!"); 30 31 PreparedStatement ps = javaConn 32 .prepareStatement("insert into jbb_posts (id_post, id_user, id_topic, " 33 + "data_post, assunto, sig, ip, post_state) values (?,?,?,?,?,?,?,?)"); 34 35 System.out.println("\tInserting data "); 36 while (rs.next()) { 37 ps.setInt(1, rs.getInt("id_post")); 38 ps.setInt(2, rs.getInt("id_user")); 39 ps.setInt(3, rs.getInt("id_topic")); 40 ps.setTimestamp(4, rs.getTimestamp("data_post")); 41 ps.setString(5, rs.getString("assunto")); 42 ps.setInt(6, rs.getInt("sig")); 43 ps.setString(7, rs.getString("ip")); 44 ps.setInt(8, rs.getInt("post_state")); 45 46 ps.addBatch(); 47 48 if (i % 10000 == 0) { 49 try { 50 ps.executeBatch(); 51 } catch (SQLException e) { 52 e.printStackTrace(); 53 } 54 ; 55 } 56 57 System.out.print("."); 58 } 59 System.out.println("\n"); 60 61 try { 62 ps.executeBatch(); 63 } catch (SQLException e) { 64 System.out.println("\n\n" + e.getNextException().getMessage()); 65 } 66 67 ps.close(); 68 stm.close(); 69 rs.close(); 70 phpConn.close(); 71 javaConn.close(); 72 System.out.print("Done!\n\n"); 73 } 74 } | Popular Tags |