資源簡介
這個是整理的小工具
通過Eclipse添加到項目,可執行!
代碼執行效率很高,能將指定MySql數據庫導出到SqlLite文件。
希望能幫到你!

代碼片段和文件信息
package?com.app.mysql2sqlite;
import?java.sql.Connection;
import?java.sql.Date;
import?java.sql.DriverManager;
import?java.sql.PreparedStatement;
import?java.sql.ResultSet;
import?java.sql.ResultSetmetaData;
import?java.sql.SQLException;
import?java.util.HashMap;
import?java.util.Map;
import?java.util.Vector;
public?class?Mysql2Sqlite?{
private?static?Connection?getMysqlConnection()?{
Connection?conn?=?null;
try?{
Class.forName(“com.mysql.jdbc.Driver“);
conn?=?DriverManager.getConnection(“jdbc:mysql://localhost:3306/newappsystem“?“root“?“ciwong“);
}?catch?(SQLException?e)?{
e.printStackTrace();
}?catch?(ClassNotFoundException?e)?{
e.printStackTrace();
}
return?conn;
}
private?static?Connection?getSqliteConnection()?{
Connection?conn?=?null;
try?{
Class.forName(“org.sqlite.JDBC“);
conn?=?DriverManager.getConnection(“jdbc:sqlite:D:\\newappstore.db“);
}?catch?(SQLException?e)?{
e.printStackTrace();
}?catch?(ClassNotFoundException?e)?{
e.printStackTrace();
}
return?conn;
}
private?static?void?closeDBConn(Connection?connMysql?Connection?connSqlite)?throws?SQLException?{
connMysql.close();
connSqlite.close();
}
private?static?void?showMysqlTables(Connection?connMysql?Vector?tabs)?throws?SQLException?{
String?strSql?=?“show?tables?“;
PreparedStatement?ps?=?connMysql.prepareStatement(strSql);
ResultSet?rs?=?ps.executeQuery();
while?(rs.next())?{
String?tab?=?rs.getString(1);
tabs.add(tab);
}
}
private?static?void?createSqliteTabs(Connection?connMysql?Connection?connSqlite?Vector?tabs)?throws?SQLException?{
for?(String?tab?:?tabs)?{
String?strSql?=?“desc?“?+?tab;
PreparedStatement?ps?=?connMysql.prepareStatement(strSql);
ResultSet?rs?=?ps.executeQuery();
int?colCnt?=?0;
int?keyCnt?=?0;
String?priKeyStr?=?“primary?key?(“;
String?createTabDDL?=?““;
createTabDDL?=?“create?table?“?+?tab?+?“?(“;
while?(rs.next())?{
String?Field?=?rs.getString(1);
String?Type?=?rs.getString(2);
String?Key?=?rs.getString(4);
createTabDDL?+=?(colCnt?==?0???““?:?““)?+?Field?+?“?“?+
(Type.startsWith(“bit“)???“bool“?:?Type);
if?(Key.equals(“PRI“))?{
priKeyStr?+=?((keyCnt?==?0)???““?:?““)?+?Field;
keyCnt++;
}
colCnt++;
}
if?(keyCnt?>?0)?{
priKeyStr?+=?“)?“;
createTabDDL?+=?“?“+?priKeyStr;
}
createTabDDL?+=?“)?“;
PreparedStatement?psSqliteCreate?=?connSqlite.prepareStatement(createTabDDL);
psSqliteCreate.executeUpdate();
}
}
private?static?void?tranData(Connection?connMysql?Connection?connSqlite?Vector?tabs)?throws?SQLException?{
for?(String?tab?:?tabs)?{
String?strSel?=?“select?*?from?“?+?tab;
PreparedStatement?ps?=?connMysql.prepareStatement(strSel);
PreparedStatement?psInsert?=?null;
ResultSet?rs?=?ps.executeQuery(
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????557??2013-06-21?09:25??Mysql2Sqlite\.classpath
?????文件????????388??2013-06-20?18:02??Mysql2Sqlite\.project
?????文件?????????91??2013-06-21?16:07??Mysql2Sqlite\.settings\org.eclipse.core.resources.prefs
?????文件????????598??2013-06-20?18:02??Mysql2Sqlite\.settings\org.eclipse.jdt.core.prefs
?????文件???????7837??2013-06-26?11:04??Mysql2Sqlite\bin\com\app\mysql2sqlite\Mysql2Sqlite.class
?????文件?????848401??2013-06-20?18:07??Mysql2Sqlite\lib\mysql-connector-java-5.1.25-bin.jar
?????文件????4504048??2013-06-26?09:30??Mysql2Sqlite\lib\mysql2sqllite.jar
?????文件????3702257??2013-06-20?18:11??Mysql2Sqlite\lib\sqlite-jdbc-3.7.15-SNAPSHOT.jar
?????文件???????5946??2013-06-26?11:04??Mysql2Sqlite\src\com\app\mysql2sqlite\Mysql2Sqlite.java
?????目錄??????????0??2013-06-21?09:25??Mysql2Sqlite\bin\com\app\mysql2sqlite
?????目錄??????????0??2013-06-20?20:50??Mysql2Sqlite\src\com\app\mysql2sqlite
?????目錄??????????0??2013-06-21?09:25??Mysql2Sqlite\bin\com\app
?????目錄??????????0??2013-06-20?20:50??Mysql2Sqlite\src\com\app
?????目錄??????????0??2013-06-21?09:25??Mysql2Sqlite\bin\com
?????目錄??????????0??2013-06-20?20:50??Mysql2Sqlite\src\com
?????目錄??????????0??2013-06-21?16:07??Mysql2Sqlite\.settings
?????目錄??????????0??2013-06-21?09:25??Mysql2Sqlite\bin
?????目錄??????????0??2013-06-26?09:30??Mysql2Sqlite\lib
?????目錄??????????0??2013-06-20?20:50??Mysql2Sqlite\src
?????目錄??????????0??2013-06-20?20:50??Mysql2Sqlite
-----------?---------??----------?-----??----
??????????????9070123????????????????????20
- 上一篇:android手機安全衛士--源碼
- 下一篇:java源代碼,java源代碼
評論
共有 條評論