美文网首页
坑爹奇葩的jdbc getColumnName(index)竟然

坑爹奇葩的jdbc getColumnName(index)竟然

作者: 吉凶以情迁 | 来源:发表于2021-12-13 16:11 被阅读0次
    /**
     * Get the designated column's name.
     *
     * @param column the first column is 1, the second is 2, ...
     * @return column name
     * @exception SQLException if a database access error occurs
     */
    String getColumnName(int column) throws SQLException;

    /**
     * Get the designated column's table's schema.
     *
     * @param column the first column is 1, the second is 2, ...
     * @return schema name or "" if not applicable
     * @exception SQLException if a database access error occurs
     */
    String getSchemaName(int column) throws SQLException;

实现


    /**
     * Return the column descriptor given a column index.
     *
     * @param column The column index (from 1 .. n).
     * @return The column descriptor as a <code>ColInfo<code>.
     * @throws SQLException
     */
    ColInfo getColumn(int column) throws SQLException {
        if (column < 1 || column > columnCount) {
            throw new SQLException(
                    Messages.get("error.resultset.colindex",
                            Integer.toString(column)), "07009");
        }

        return columns[column - 1];
    }


我本来是写的从1开始的,后面写webapi我自己都纳闷,额,我怎么给写成1了,怎么这么低级的错误,我就把哪个地方改成了0 ,把<=count 改成count,然后切换为jdbc模式的时候出错了,坑爹,坑爹,必须记录下来,搞得我改过来改过去


  while (resultSet.next()) {
            ResultSetMetaData rsMetaData = resultSet.getMetaData();
            //检索列名列表
            LinkedHashMap<String, Object> hashMap = new LinkedHashMap<>();
            int count = rsMetaData.getColumnCount();
            keymaploop:
            for (int i = 1; i <= count; i++) {// getColumn 从1 开始
                String columnName = rsMetaData.getColumnName(i);
                int columnType = rsMetaData.getColumnType(i);
                Object object = null;
                if (columnType == Types.VARBINARY) {
                    object = resultSet.getBinaryStream(columnName);
                } else if (columnType == Types.CLOB) {
                    Clob clob = resultSet.getClob(columnName);
                    object = ClobToString(clob);
                } else if (columnType == Types.BLOB) {
                    Blob blob = resultSet.getBlob(columnName);
                    if (blob != null) {
                        object = blob.getBinaryStream();
                    }
                } else {
                    object = resultSet.getObject(columnName);
                }
                if (onlyOneColumn) {
                    String result = String.valueOf(object == null ? "" : object);
                    if (!TextUtils.isEmpty(result)) {
                        list.add(result);
                    }
                    break keymaploop;//只查询一列作为list
                } else {
                    if (object instanceof InputStream) {
                        hashMap.put(columnName, new JDBCWrapper.InputStreamWrap((InputStream) object, columnName));
                    } else if (object instanceof Array) {
                        hashMap.put(columnName, object);
                    } else {
                        hashMap.put(columnName, String.valueOf(object == null ? "" : object));
                    }

                }
            }
            if (!onlyOneColumn) {
                list.add(hashMap);//否则返回一个字符串list
            }


        }

除此之外,注册输出函数第一个index=1是返回值,也是从1开始的,就问奇葩不奇葩。

相关文章

  • 坑爹奇葩的jdbc getColumnName(index)竟然

    实现 我本来是写的从1开始的,后面写webapi我自己都纳闷,额,我怎么给写成1了,怎么这么低级的错误,我就把哪个...

  • 历史小白读《史记》(二)——亲手害死儿子的极品爹

    都说虎毒不食子,历来是儿子坑爹,哪有爹坑儿子?可春秋时期,就出了些奇葩的爹,尽把儿子往死里整。 先说说卫国的卫宣公...

  • SparkSQL读写jdbc一些鲜为人知的事儿

    最近部门正在使用Spark做ETL,在使用JDBC作为DataSource的时候遇到了一些坑爹的问题,本文主要分享...

  • 坑爹

    坑爹…豆瓣就是个坑爹货

  • 坑儿子的奇葩母亲

    坑儿子的奇葩母亲 大家都知道网络流行语“坑爹”,此词含义广泛,其中就有在团队协作中被“出卖”或“戏耍”的含义。这里...

  • 坑爹的爹坑

    01 村里的奇葩事,真事!就是奇葩的让人咂舌。张明白有一个‘奇葩’的爹,人称张算计。 清明节,村里的张算计死了。人...

  • 今日奇葩大盘点

    Ruqiu (秋之韵) 奇葩天天有,今日特别多。居家无聊,故选其一二品之。 奇葩一、实力坑爹,大意失荆州 抗击疫情...

  • 这几款坑爹搞笑无节操的游戏没玩过会后悔

    “坑”字当道,坑爹的事情真是多不胜数。为了迎合潮流游戏开发商也不甘示弱,纷纷推出各种玩法创新,又恶搞,没节操的奇葩...

  • 坑爹?爹挖的坑

    坑爹的儿子都是被爹坑的 白米先生 字数 474 · 阅读 1 2020-06-13 09:35 说起来像绕口令。 ...

  • 坑爹的爹

    2023年1月31日 星期三 下午4:44 昨晚上娃爹又一晚上没回来了! 第一次一晚上跟他正面对决!从来没有这么直...

网友评论

      本文标题:坑爹奇葩的jdbc getColumnName(index)竟然

      本文链接:https://www.haomeiwen.com/subject/fyojfrtx.html