You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.6 KiB
104 lines
2.6 KiB
package de.memtext.db; |
|
|
|
import java.sql.DriverManager; |
|
import java.sql.SQLException; |
|
import java.util.Iterator; |
|
import java.util.List; |
|
|
|
import de.memtext.util.StringUtils; |
|
|
|
public class DBComparison { |
|
|
|
private DBComparison() { |
|
super(); |
|
} |
|
public static void main(String a[]) { |
|
try { |
|
Class.forName("org.hsqldb.jdbcDriver"); |
|
|
|
java.sql.Connection con = |
|
DriverManager.getConnection( |
|
"jdbc:hsqldb:hsql://localhost:9000", |
|
"sa", |
|
""); |
|
DBAccess.addConnection("ssc", con); |
|
java.sql.Connection con2 = |
|
DriverManager.getConnection( |
|
"jdbc:hsqldb:hsql://localhost:9500", |
|
"sa", |
|
""); |
|
DBAccess.addConnection("ssc-test", con2); |
|
compare("ssc", "ssc-test"); |
|
|
|
} catch (ClassNotFoundException e) { |
|
e.printStackTrace(); |
|
} catch (SQLException e) { |
|
e.printStackTrace(); |
|
} catch (Exception e) { |
|
e.printStackTrace(); |
|
} |
|
|
|
} |
|
private static void compare(String db1, String db2) { |
|
System.out.println("Start comparing..."); |
|
StringBuffer fineTables = |
|
new StringBuffer("The following tables are fine: "); |
|
List tableList = DBAccess.get(db1).getTableList(); |
|
boolean isOk = false; |
|
for (Iterator it = tableList.iterator(); it.hasNext();) { |
|
String table = (String) it.next(); |
|
|
|
if (DBAccess.get(db2).hasTable(table)) { |
|
isOk = true; |
|
if (DBAccess.get(db1).getColumnCount(table) |
|
!= DBAccess.get(db2).getColumnCount(table)) { |
|
System.out.println( |
|
"Table " |
|
+ table |
|
+ " has a different number of columns"); |
|
isOk = false; |
|
} else { |
|
List colList = DBAccess.get(db1).getColumnNames(table); |
|
for (Iterator it2 = colList.iterator(); it2.hasNext();) { |
|
String colname = (String) it2.next(); |
|
if (!DBAccess.get(db2).hasColumn(table, colname)) { |
|
System.out.println( |
|
"Table " |
|
+ table |
|
+ " in " |
|
+ db2 |
|
+ " doesn't have column:" |
|
+ colname); |
|
isOk = false; |
|
} else { |
|
|
|
if (DBAccess.get(db1).getColumnType(table, colname) |
|
!= DBAccess.get(db2).getColumnType( |
|
table, |
|
colname)) { |
|
System.out.println( |
|
"Table " |
|
+ table |
|
+ " column:" |
|
+ colname |
|
+ " are of different types"); |
|
isOk = false; |
|
} |
|
|
|
} |
|
} |
|
if (isOk) |
|
fineTables.append(table + ","); |
|
} |
|
|
|
} else { |
|
System.out.println(db2 + " doesn't contain table:" + table); |
|
} |
|
} |
|
StringUtils.deleteLastChar(fineTables); |
|
System.out.println(fineTables); |
|
System.out.println("..done"); |
|
} |
|
} |
|
|
|
//Created on 11.02.2004 at 13:19:36
|