政府机关packageimport

连接informix库进行数据比对

package cinda99;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class ifx { /**
* @param args
* @throws IOException
* @throws NumberFormatException public static void main(String[] args) throws NumberFormatException, IOException {

   String url = "jdbc:informix-sqli://10.2.3.36:7788/phase2db:INFORMIXSERVER=dep;NEWCODESET=gbk,8859-1,819";
        String user = "admis2";
        String pw = "admis123";
        Connection con = null;
        Statement stmt = null;
        String query = "select tabname from systables where owner = 'admis2' and tabtype = 'T' and tabname not like 'temp%' and " +
           "tabname not like 'tmp%' and tabname not like 'test%' and tabname not like 'linux%'";
        List lis = new ArrayList();
        List lis1 = new ArrayList();
        int i = 0;
        try {
        Class.forName("com.informix.jdbc.IfxDriver");//导入数据库驱动
        } catch(java.lang.ClassNotFoundException e) {              System.err.print("ClassNotFoundException: ");
             System.err.println(e.getMessage());         try {
                con = DriverManager.getConnection(url, user, pw);                 stmt = con.createStatement();
           //Create 一个声明
                ResultSet rs = stmt.executeQuery(query);              while (rs.next()) {
             String s = rs.getString("tabname");
           lis.add(s.toLowerCase());
           lis1.add(s.toLowerCase());            i++;
           /*String t = rs.getString(1);
           String l = rs.getString(2);
           System.out.println(t + " " + l);*/
           /*jdbc提供了两种方法识别字段,一种是使用getXXX(注意这里的getXXX表示取不同类型字段的不同的方法)获得字段名,            /*你可以访问这个连接获得getxxx的用法:http://java.sun.com/docs/books/t ... etrievingTable.html*/            stmt.close();
           con.close();
           if(lis!=null&&lis.size()!=0){
            for(i=0;i                    //System.out.println(lis.get(i));             }
             //System.out.println("--------------------------");            } catch(SQLException ex) {
           System.err.println("SQLException: " + ex.getMessage());            }                    File file = new File("c:/erwin.txt");//源文件位置
           FileReader fr = new FileReader(file);//创建文件输入流
           BufferedReader in = new BufferedReader(fr);//包装文件输入流,可整行读取
           String line = in.readLine();//读取第一行
           List list = new ArrayList();
           List list1 = new ArrayList();
           while(line!=null){//如果line为空说明读完了
            list.add(line.toLowerCase());
            list1.add(line.toLowerCase());
            //System.out.println(line);
            line = in.readLine();            //System.out.println("&&&&&&&&&&&&&&&&&");                 
           //System.out.println(lis.size());
           lis.removeAll(list);
           //System.out.println(lis.size());           
           //System.out.println(list1.size());
           list1.removeAll(lis1);
           //System.out.println(list1.size());            //System.out.println("以下为Informix中存在,ERWIN中不存在的表");
           for(int j=0;j            //System.out.println(lis.get(j));            //System.out.println("以下为ERWIN中存在,Informix中不存在的表");
           for(int j=0;j            //System.out.println(list1.get(j));           
           System.out.println("以下是为空的表");
           Connection con1 = null;
                Statement stmt1 = null;
                try {
                    con1 = DriverManager.getConnection(url, user, pw);                     stmt1 = con1.createStatement();
               //Create 一个声明
                    for(int j=0;j                String sql = "select count(*) as zk from "+lis.get(j).toString().trim();
                //System.out.println(sql);
                try {
           ResultSet rs1 = stmt1.executeQuery(sql);
           int q = 1;
           if(rs1.next()){
            q = rs1.getInt("zk");           
           if(q==0){             System.out.println(lis.get(j)+" 为空");
           }else{
            System.out.println(lis.get(j)+" 不为空");           } catch (SQLException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();                     }
               stmt1.close();
               con1.close();
               System.out.println("搞定!");                } catch(SQLException ex) {
               System.err.println("SQLException: " + ex.getMessage());                }            }         
           }
参与0

0同行回答

“答”则兼济天下,请您为题主分忧!

提问者

fdew32
系统工程师informixchina

问题状态

  • 发布时间:2011-08-08
  • 关注会员:0 人
  • 问题浏览:2618
  • X社区推广