Obtaining Table metadata from mysql in java

痴心易碎 提交于 2019-12-01 01:55:43

You may want to check into what the INFORMATION_SCHEMA table within MySQL is capable of giving you. Sometimes you can use them to your advantage. I did some quick looking and nothing hit me immediately from within there.

MySQL Information Schema: http://dev.mysql.com/doc/refman/5.6/en/information-schema.html

As @technocrat said, check this query on information_schema

SELECT column_name, column_type FROM INFORMATION_SCHEMA.columns where table_schema='[Table schema]' and table_name='[Table Name]'

Refer below article:

Will help you to know understand an example from JDBC Metadata Get table

http://roseindia.net/jdbc/Jdbc-meta-data-get-tables.shtml

I may be off the mark with what you're asking but is mysql command show columns in <tablename> of any use? http://dev.mysql.com/doc/refman/5.1/en/show-columns.html for more info.

In the case of INT(8), you should know that the 8 is not a size limit. That's a frequent misconception by MySQL users. The argument to INT-like data types is only a hint to SQL to pad the values if they have fewer digits than the argument. It's normally used only for ZEROFILL.

CREATE TABLE foo ( i1 INT(8) ZEROFILL, i2 INT(16) ZEROFILL );
INSERT INTO foo VALUES (1234, 1234);
SELECT * FROM foo;
+----------+------------------+
| i1       | i2               |
+----------+------------------+
| 00001234 | 0000000000001234 | 
+----------+------------------+

The value 8 vs. 16 does not change the storage space required by an INT, nor the range of values it supports. The INT data type is always 32-bits, and always allows values from -231 to 231-1, regardless of the argument you give it.

Likewise TINYINT is always 8 bits, SMALLINT is always 16 bits, MEDIUMINT is always 24 bits, and BIGINT is always 64 bits.

The 10 value you get is the numeric precision, not a size limit. That is, a 32-bit value may use up to 10 digits when displayed in base-10:

SELECT LENGTH(POW(2,31));
+-------------------+
| LENGTH(POW(2,31)) |
+-------------------+
|                10 | 
+-------------------+
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!