KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > javabb > migration > betweendbs > Jbb_topics


1 /**
2  * Script de migração phpBB -> JavaBB
3  * @author Lucas Teixeira - lucas@javabb.org
4  */

5
6 package org.javabb.migration.betweendbs;
7 import java.sql.Connection JavaDoc;
8 import java.sql.PreparedStatement JavaDoc;
9 import java.sql.ResultSet JavaDoc;
10 import java.sql.SQLException JavaDoc;
11 import java.sql.Statement JavaDoc;
12
13 public class Jbb_topics extends Jbb_Convert {
14     
15     public void convert() throws ClassNotFoundException JavaDoc, SQLException JavaDoc {
16         sql = "select * from jbb_topics";
17         
18         System.out.println("TABLE JBB_TOPICS.");
19         Connection JavaDoc phpConn = this.getDbOrigin();
20         Statement JavaDoc stm = phpConn.createStatement();
21         System.out.println("\tReading data");
22         ResultSet JavaDoc rs = stm.executeQuery(sql);
23         long i = 0;
24
25         Connection JavaDoc 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 JavaDoc 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 // Statement stmt = javaConn.createStatement();
38
while (rs.next()) {
39             
40             
41 // String sqlI = "insert into jbb_topics (id_topic, id_user, " +
42
// "id_forum, title_topic, data_topico, visualizacoes, respostas, topic_status" +
43
// "topic_model, last_post_date, last_post_id, last_post_page, last_post_user_id, last_post_user_name, notify_me) " +
44
// "values ("+ rs.getInt("id_topic") +","+ rs.getInt("id_user") +","+ rs.getInt("id_forum") +",'"+ rs.getString("title_topic") +"'," +
45
// "'"+ rs.getTimestamp("data_topico") +"',"+ rs.getInt("visualizacoes") +"," +
46
// ""+ rs.getInt("respostas") +","+ rs.getInt("topic_status") +"," +
47
// ""+ rs.getInt("topic_model") +",'"+ rs.getTimestamp("last_post_date") +"'," +
48
// ""+ rs.getInt("last_post_id") +","+ rs.getInt("last_post_page") +"," +
49
// ""+ rs.getInt("last_post_user_id") +",'"+ rs.getString("last_post_user_name") +"',"+ rs.getInt("notify_me") +");";
50
// System.out.println(sqlI);
51
// stmt.executeUpdate(sqlI);
52

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