选择所有具有匹配列名的表

时间:2019-08-21 18:07:36

标签: java mysql ucanaccess

是否有一种方法可以使用UCANACESS在数据库中与特定名称匹配的所有列上选择并执行查询

我尝试使用Find all tables that have X column name

上的MYSQL方法
String sql = "SELECT DISTINCT table_name FROM INFORMATION_SCHEMA.COLUMNS WHERE column_name= 'CID'";



        ResultSet rs = readID.executeQuery(sql);
        System.out.println("This plugin has successfully connected to the database...");
        do {
            userInput2 = JOptionPane.showInputDialog(null,"HIPAA Main Menu \n1. Encrypt the database. \n2. Decrypt the database.\n3. Exit the program.\n(Make a selection by entering 1, 2, or 3)");
            choice = Integer.parseInt(userInput2);
            switch (choice) {
                case 1 :
                    while (rs.next()) {
                        ID = rs.getString("CID");
                        rs.updateString("CID", encodedID(ID,aesKey,cipher));
                        rs.updateRow();
                        x++;
                    }
                    dbConnection.commit();

ResultSet rs = readID.executeQuery(sql);

我希望代码可以连接到数据库中名为CID的任何列,然后获取该列中的字符串,但是,我收到以下错误...

此插件已成功连接到数据库... net.ucanaccess.jdbc.UcanaccessSQLException:UCAExc ::: 4.0.4找不到列:CID     在net.ucanaccess.jdbc.UcanaccessResultSet.getString(UcanaccessResultSet.java:782)     在Hipaa.main(Hipaa.java:63) 造成原因:net.ucanaccess.jdbc.UcanaccessSQLException:UCAExc ::: 4.0.4找不到列:CID     在net.ucanaccess.jdbc.UcanaccessResultSet.getObject(UcanaccessResultSet.java:649)     在net.ucanaccess.jdbc.UcanaccessResultSet.getString(UcanaccessResultSet.java:776)     ...还有1个

1 个答案:

答案 0 :(得分:1)

尝试将此行更改为:

字符串sql =“从INFORMATION_SCHEMA.COLUMNS WHERE column_name ='CID'中选择DISTINCT table_name”;

然后尝试再次运行它 希望这会成功