arraylist值与excelsheet行值进行比较

时间:2017-12-12 12:04:51

标签: java mysql excel arraylist comparison

我想比较每行从mysql数据库派生的值和excel表值。

我实现了直到从MysqlDb获取值并存储到Arraylist中。现在我想将这些值与excel文件进​​行比较。我希望解释好,让我知道,如果没有理解。 请查看我的代码:

public class DbConnection {

    public static Connection connectJDBCToAWSEC2() {

        System.out.println("----MySQL JDBC Connection Testing -------");

        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println("Where is your MySQL JDBC Driver?");
            e.printStackTrace();
            return null;
        }

        System.out.println("MySQL JDBC Driver Registered!");
        Connection connection = null;

        try {
            /*
             * connection = DriverManager.
             * getConnection("jdbc:mysql://52.53.283.64:3306/testdb", "testadmin",
             * "Stg@work");
             */
            connection = DriverManager.getConnection("jdbc:mysql://13.55.218.42/test_permit_data", "automationadmin",
                    "Make!tYours1976");
        } catch (SQLException e) {
            System.out.println("Connection Failed!:\n" + e.getMessage());
        }

        if (connection != null) {
            System.out.println("SUCCESS!!!! You made it, take control your database now!");
            return connection;
        } else {
            System.out.println("FAILURE! Failed to make connection!");
            return connection;
        }
    }

    public static void connectJDBCToAWSEC21() {

        System.out.println("----MySQL JDBC Connection Testing -------");

        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println("Where is your MySQL JDBC Driver?");
            e.printStackTrace();
            return;
        }

        System.out.println("MySQL JDBC Driver Registered!");
        Connection connection = null;

        try {
            connection = DriverManager.getConnection(""jdbc:mysql://52.53.283.64:3306/testdb", "testadmin",
                    "Stg@work");
        } catch (SQLException e) {
            System.out.println("Connection Failed!:\n" + e.getMessage());
        }

        if (connection != null) {
            System.out.println("SUCCESS!!!! You made it, take control     your database now!");
        } else {
            System.out.println("FAILURE! Failed to make connection!");
        }

    }

    public static ResultSet runQueryResultSet(Connection con, String sql) {
        Statement statement = null;
        ResultSet rs = null;
        int col = 0;
        try {

            System.out.println("Creating statement...");
            statement = con.createStatement();
            rs = statement.executeQuery(sql);
            java.sql.ResultSetMetaData meta = rs.getMetaData();
            // Getting column count from DB
            int colCount = meta.getColumnCount();
            // creating array list to store the values
            ArrayList<String> arrayList = new ArrayList<String>();
            // Getting values from db by each column
            while (rs.next()) {

                for (col = 2; col <= colCount - 2; col++) {

                    arrayList.add(rs.getString(col));
                    if (rs.getObject(col) == null) {
                        System.out.print(" NULL ");
                    } else {
                        System.out.print(" " + rs.getObject(col));
                    }

                }
            }
        }
    }
}

0 个答案:

没有答案