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_forum extends Jbb_Convert { 14 15 public void convert() throws ClassNotFoundException , SQLException { 16 sql = "SELECT * FROM jbb_forum ORDER BY id_forum;"; 17 System.out.println("TABLE JBB_FORUM."); 18 Connection phpConn = this.getDbOrigin(); 19 Statement stm = phpConn.createStatement(); 20 System.out.println("\tReading data"); 21 ResultSet rs = stm.executeQuery(sql); 22 23 Connection javaConn = this.getDbDest(); 24 25 javaConn.createStatement().executeUpdate("delete from jbb_forum"); 27 System.out.println("delete from jbb_forum is OK!"); 28 29 PreparedStatement ps = javaConn.prepareStatement("INSERT INTO jbb_forum (id_forum, nome, descricao, " + 30 "forum_status, forum_order, id_category, topic_count, post_count, last_post_id, last_page_post," + 31 "last_post_user_name, last_post_user_id, last_post_date, last_topic_id) " + 32 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?);"); 33 34 System.out.println("\tInserting data "); 35 while (rs.next()) { 36 ps.setInt ( 1, rs.getInt("id_forum")); 37 ps.setString ( 2, rs.getString("nome")); 38 ps.setString ( 3, rs.getString("descricao")); 39 ps.setInt ( 4, rs.getInt("forum_status")); 40 ps.setInt ( 5, rs.getInt("forum_order")); 41 ps.setInt ( 6, rs.getInt("id_category")); 42 ps.setInt ( 7, rs.getInt("topic_count")); 43 ps.setInt ( 8, rs.getInt("post_count")); 44 ps.setInt ( 9, rs.getInt("last_post_id")); 45 ps.setInt ( 10, rs.getInt("last_page_post")); 46 ps.setString ( 11, rs.getString("last_post_user_name")); 47 ps.setInt ( 12, rs.getInt("last_post_user_id")); 48 ps.setTimestamp ( 13, rs.getTimestamp("last_post_date")); 49 ps.setInt ( 14, rs.getInt("last_topic_id")); 50 51 ps.executeUpdate(); 52 System.out.print("."); 53 } 54 System.out.println("\n"); 55 56 ps.close(); 57 stm.close(); 58 rs.close(); 59 phpConn.close(); 60 javaConn.close(); 61 System.out.print("Done!\n\n"); 62 } 63 } 64 | Popular Tags |