Java如何获取ResultSet结果中的每一列的数据类型

示例代码片段:

			ResultSet resultSet = statement.executeQuery(sql);
			ResultSetMetaData metaData = resultSet.getMetaData();
			System.out.println(metaData.getColumnCount());
			for (int i = 1 ; i <= metaData.getColumnCount(); i ++) {
				System.out.println(metaData.getColumnType(i));
				System.out.println(metaData.getColumnTypeName(i));
			}

类型清单如下:

  • -7 BIT
  • -6 TINYINT
  • -5 BIGINT
  • -4 LONGVARBINARY
  • -3 VARBINARY
  • -2 BINARY
  • -1 LONGVARCHAR
  • 0 NULL
  • 1 CHAR
  • 2 NUMERIC
  • 3 DECIMAL
  • 4 INTEGER
  • 5 SMALLINT
  • 6 FLOAT
  • 7 REAL
  • 8 DOUBLE
  • 12 VARCHAR
  • 91 DATE
  • 92 TIME
  • 93 TIMESTAMP
  • 1111 OTHER

参考链接:https://alvinalexander.com/java/edu/pj/jdbc/recipes/ResultSet-ColumnType.shtml

posted @ 2018-09-10 08:07  zifeiy  阅读(9679)  评论(0编辑  收藏  举报