本帖最后由 Tiyz 于 2011-10-26 17:21 编辑
/* 注意:将附件文件夹 upload 放置到 data/attachment/portal
*
*/
package mysqldataconverter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Administrator
*/
public class MysqlDataConverter {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
// TODO code application logic here
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/wuunion?user=root&useUnicode=true&characterEncoding=UTF-8");
Statement statementDedecms = conn.createStatement();
Statement statementDiscuzx = conn.createStatement();
String sqlDiscuzx = "TRUNCATE TABLE `pre_portal_category`";
statementDiscuzx.executeUpdate(sqlDiscuzx);
String sqlDedecms = "SELECT * FROM `dede_arctype`";
ResultSet resultDedecms = statementDedecms.executeQuery(sqlDedecms);
while (resultDedecms.next()) {
String id = resultDedecms.getString("id");
String reid = resultDedecms.getString("reid");
String sortrank = resultDedecms.getString("sortrank");
String typename = resultDedecms.getString("typename");
sqlDiscuzx = "INSERT INTO `pre_portal_category` (`catid`, `upid`,`catname`,`displayorder`,`description`,`keyword`,`seotitle`)VALUES ('" + id + "', '" + reid + "', '" + typename + "', '" + sortrank + "','','','')";
statementDiscuzx.executeUpdate(sqlDiscuzx);
}
sqlDiscuzx = "TRUNCATE TABLE `pre_portal_article_title`";
statementDiscuzx.executeUpdate(sqlDiscuzx);
sqlDiscuzx = "TRUNCATE TABLE `pre_portal_article_content`";
statementDiscuzx.executeUpdate(sqlDiscuzx);
sqlDiscuzx = "TRUNCATE TABLE `pre_portal_article_count`";
statementDiscuzx.executeUpdate(sqlDiscuzx);
sqlDedecms = "SELECT * FROM `dede_archives` LEFT JOIN `dede_addonarticle` ON `dede_archives`.`id` = `dede_addonarticle`.`aid`";
resultDedecms = statementDedecms.executeQuery(sqlDedecms);
while (resultDedecms.next()) {
String id = resultDedecms.getString("id");
String typeid = resultDedecms.getString("typeid");
String sortrank = resultDedecms.getString("sortrank");
String title = resultDedecms.getString("title");
String body = resultDedecms.getString("body");
if (body != null) {
body = body.replaceAll("\'", "\"").replaceAll("/main", "data/attachment/portal");
}
String description = resultDedecms.getString("description");
sqlDiscuzx = "INSERT INTO `pre_portal_article_title` (`aid`, `catid`,`uid`,`username`,`title`,`summary`,`dateline`)VALUES ('" + id + "', '" + typeid + "', '1','admin','" + title + "','" + description + "', '" + sortrank + "')";
statementDiscuzx.executeUpdate(sqlDiscuzx);
sqlDiscuzx = "INSERT INTO `pre_portal_article_content` (`cid`, `aid`,`content`,`dateline`)VALUES('" + id + "','" + id + "','" + body + "', '" + sortrank + "')";
statementDiscuzx.executeUpdate(sqlDiscuzx);
sqlDiscuzx = "INSERT INTO `pre_portal_article_count` (`aid`, `catid`,`dateline`)VALUES('" + id + "','" + typeid + "', '" + sortrank + "')";
statementDiscuzx.executeUpdate(sqlDiscuzx);
}
sqlDedecms = "SELECT * FROM `dede_addonsoft`";
resultDedecms = statementDedecms.executeQuery(sqlDedecms);
while (resultDedecms.next()) {
String id = resultDedecms.getString("aid");
String softlinks = resultDedecms.getString("softlinks");
if (softlinks != null) {
softlinks = softlinks.replaceAll("\'", "\"").replaceAll("/main", "data/attachment/portal");
softlinks = softlinks.replaceAll("\\{/.*\\}", "").replaceAll("\\{.*\\}", "");
softlinks = "<a href = \"" + softlinks + "\"><U>Download</U></a>";
}
String introduce = resultDedecms.getString("introduce");
if (introduce != null) {
introduce = introduce.replaceAll("\'", "\"");
}
sqlDiscuzx = "UPDATE `pre_portal_article_title` SET `summary` = '" + introduce + "' WHERE aid = '" + id + "'";
statementDiscuzx.executeUpdate(sqlDiscuzx);
sqlDiscuzx = "UPDATE `pre_portal_article_content` SET `content` = '" + introduce + "<br />" + softlinks + "' WHERE aid = '" + id + "'";
statementDiscuzx.executeUpdate(sqlDiscuzx);
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(MysqlDataConverter.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(MysqlDataConverter.class.getName()).log(Level.SEVERE, null, ex);
} catch (NullPointerException ex) {
Logger.getLogger(MysqlDataConverter.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
|