📄 dbjframe.java
字号:
{
ParseScope("2",tabColumnCheckBox.getText());
}
if(indexCheckBox.isSelected())
{
ParseScope("2",indexCheckBox.getText());
}
}else{
tabColumnCheckBox.setEnabled(false);
indexCheckBox.setEnabled(false);
}
}
});
getContentPane().add(tableCheckBox);
tabColumnCheckBox=new JCheckBox("TABCOLUMN");
tabColumnCheckBox.setEnabled(false);
tabColumnCheckBox.setBounds(260,295,145,25);
tabColumnCheckBox.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
if(tabColumnCheckBox.isSelected())
{
scope="";
ParseScope("1",tableCheckBox.getText());
ParseScope("2",tabColumnCheckBox.getText());
if(indexCheckBox.isSelected())
ParseScope("2",indexCheckBox.getText());
}
}
});
getContentPane().add(tabColumnCheckBox);
indexCheckBox=new JCheckBox("INDEX");
indexCheckBox.setEnabled(false);
indexCheckBox.setBounds(440,295,100,25);
indexCheckBox.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
if(indexCheckBox.isSelected())
{
scope="";
ParseScope("1",tableCheckBox.getText());
if(tabColumnCheckBox.isSelected())
ParseScope("2",tabColumnCheckBox.getText());
ParseScope("2",indexCheckBox.getText());
}
}
});
getContentPane().add(indexCheckBox);
compBtn = new JButton();
compBtn.setEnabled(false);
compBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try
{
showOutPut("正在进行数据库比较...");
TruncataTable(storageCon);
XMLReader.start();
DbCompare dbComp = new DbCompare(srcDao,desDao,storageDao);
String compScope = scope;
dbComp.prepareComp(compScope,0,Context.getRoot());
String owner = db1Owner.getSelectedItem()+","+db2Owner.getSelectedItem();
dbComp.doCompare(owner);
System.out.println(DbCompare.scanResult);
showOutPut("已完成");
Vector v = new Vector();
}catch (Exception e1) {
e1.printStackTrace();
}
}
});
compBtn.setBounds(285, 330, 100, 25);
getContentPane().add(compBtn);
compBtn.setText("比较");
chooseOwnerLabel = new JLabel();
chooseOwnerLabel.setBounds(5, 220, 115, 25);
getContentPane().add(chooseOwnerLabel);
chooseOwnerLabel.setText("请选择比较对象");
db1Owner = new JComboBox();
db1Owner.setBounds(195, 220, 75, 20);
db1Owner.addItem("");
getContentPane().add(db1Owner);
db2Owner = new JComboBox();
db2Owner.setBounds(375, 220, 75, 20);
db2Owner.addItem("");
getContentPane().add(db2Owner);
setvalue();
}
/**
* @param storageCon
*/
protected void TruncataTable(Connection storageCon) {
String secSql="select table_name from dba_tables where owner='"+db3UserTextField.getText()+"'";
String truncateSql="";
try {
ResultSet rs=storageCon.createStatement().executeQuery(secSql);
rs.next();
while(!rs.isAfterLast())
{
truncateSql="truncate table "+rs.getString(1);
storageCon.createStatement().execute(truncateSql);
storageCon.commit();
rs.next();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* @param string
*/
protected String ParseScope(String level,String string) {
StringBuffer strBuf=new StringBuffer();
if(level.equalsIgnoreCase("1"))
{
strBuf.append(level+string);
scope=scope+strBuf.toString();
}else if(level.equalsIgnoreCase("2"))
{
int pos=scope.indexOf(")");
if(pos==-1)
{
strBuf.append("("+level+string+")");
scope=scope+strBuf.toString();
}else
{
strBuf.append(level+string);
scope=scope.substring(0,pos)+strBuf.toString()+scope.substring(pos,scope.length());
}
}else
{
int pos=scope.indexOf(")");
strBuf.append("("+level+string+")");
scope=scope.substring(0,pos)+strBuf.toString()+scope.substring(pos,scope.length());
}
return scope;
}
protected void db1connect(String url, String user, String pwd, String drive) {
try
{
srcDao=new DAO(url,user,pwd,drive);
srcCon=srcDao.getConnection();
OWNERS1=GetOwnerFromDB(srcCon);
if(srcCon==null)
{
showOutPut("连接数据库1异常");
}
}catch(Exception e)
{
e.printStackTrace();
}
}
protected void db2connect(String url, String user, String pwd, String drive) {
try
{
desDao=new DAO(url,user,pwd,drive);
desCon=desDao.getConnection();
OWNERS2=GetOwnerFromDB(desCon);
if(desCon==null)
{
showOutPut("连接数据库2异常");
}
}catch(Exception e)
{
e.printStackTrace();
}
}
protected void db3connect(String url, String user, String pwd, String drive) {
try
{
storageDao=new DAO(url,user,pwd,drive);
storageCon=storageDao.getConnection();
if(storageCon==null)
{
showOutPut("连接数据库3异常");
}
}catch(Exception e)
{
e.printStackTrace();
}
}
private void alert()
{
JOptionPane.showMessageDialog(frame,"请检查输入参数","输入参数错误",JOptionPane.WARNING_MESSAGE);
}
private void alert(String string)
{
JOptionPane.showMessageDialog(frame,"错误",string,JOptionPane.WARNING_MESSAGE);
}
private void showOutPut(String string)
{
out.setText(out.getText()+string+"\n");
}
private String[] GetOwnerFromDB(Connection con)
{
String getOwnerSql="select username from dba_users";
String[] tempowners=new String[100];
int i=0;
try
{
ResultSet rs=con.createStatement().executeQuery(getOwnerSql);
rs.next();
while(!rs.isAfterLast())
{
tempowners[i]=rs.getString(1);
i++;
rs.next();
}
}catch(SQLException e)
{
e.printStackTrace();
}
String [] owners=new String[i];
for(int j=0;j<tempowners.length;j++)
{
if(tempowners[j]!=null)
owners[j]=tempowners[j];
}
return owners;
}
void setvalue(){
db1UrlTextField.setText("jdbc:oracle:thin:@122.136.14.113:1521:cacapro");
db1UserTextField.setText("system");
db1PwdField.setText("password");
db2UrlTextField.setText("jdbc:oracle:thin:@122.136.14.113:1521:caca");
db2UserTextField.setText("system");
db2PwdField.setText("password");
db3UrlTextField.setText("jdbc:oracle:thin:@122.136.14.166:1521:ora92");
db3UserTextField.setText("DDL");
db3PwdField.setText("DDL");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -