Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 获取jdbc元数据中的columnCount=1_Java_Jdbc - Fatal编程技术网

Java 获取jdbc元数据中的columnCount=1

Java 获取jdbc元数据中的columnCount=1,java,jdbc,Java,Jdbc,表中的列数不断出错,我做错了什么?这是代码 这不对吗?我做错了什么?如何获取特定表的列数 public int getTableInfo(String tableName, String db, Boolean columnCount, Boolean rowCount) { TABLE = tableName; Connection getTableInfoConn = this.getConnect_to_DB(db); try {

表中的列数不断出错,我做错了什么?这是代码 这不对吗?我做错了什么?如何获取特定表的列数

public int getTableInfo(String tableName, String db, Boolean columnCount,
        Boolean rowCount) {

    TABLE = tableName;

    Connection getTableInfoConn = this.getConnect_to_DB(db);

    try {
        PreparedStatement prepStatement = getTableInfoConn
                .prepareStatement("SELECT COUNT(*) FROM `" + tableName
                        + "`");

        ResultSet res = prepStatement.executeQuery();

        if ((columnCount == false) && (rowCount == false)
                || (columnCount == null) && (rowCount == false)
                || (columnCount == false) && (rowCount == null)
                || (columnCount == null) && (rowCount == null)) {

            JOptionPane.showMessageDialog(null,
                    "uno de los booleanos debe ser TRUE", null,
                    JOptionPane.ERROR_MESSAGE, null);

        } else {

            if (columnCount == false && rowCount == true
                    || columnCount == null) {

                while (res.next()) {

                    resultMetaData = res.getInt(1);
                }
            } else if (columnCount == true && rowCount == false
                    || rowCount == null) {

                metaData = res.getMetaData();



                resultMetaData = metaData.getColumnCount();


            }

        }

    } catch (SQLException e) {

        JOptionPane.showMessageDialog(null, "Error in getTableInfo():" + e);
    }

    return resultMetaData;

}
主要方法是=

public static void main(String[] args) {

    ConectorBaseDatos dbconector = new ConectorBaseDatos();

    int numFilas = dbconector.getTableInfo("arbitros","fifa", false, true);

    System.out.println("Numero de filas de arbitros es : "+ numFilas);

    int numColumnas = dbconector.getTableInfo("arbitros", "fifa", true, false);

   System.out.println("numero de columnas es : " + numColumnas);
}

为什么columnCount=1

您在这里发出的查询是:

select count(*) from arbitros;
结果将是一列,一行,只保留arbitros中的行数。该结果有一个名为count*或类似的列

如果需要arbitros中的列数,则需要的查询是:

select * from arbitros;