2016-03-05 29 views

回答

3

假设一个测试表与

CREATE TABLE tableA 
( id int auto_increment primary key, 
    w INT(8) ZEROFILL NOT NULL, 
    x INT(8) NOT NULL, 
    y int signed not null, 
    z int unsigned not null, 
    shortBinaryCharString char(10) binary not null, 
    myBlob blob(10000) null 
); 

如从here大多借用为起点产生。

我会建议使用标准查询在INFORMATION_SCHEMA数据库中的表。如

select table_schema, table_name, column_name, ordinal_position, is_nullable, data_type, 
character_set_name, collation_name, column_type, column_key, extra 
from INFORMATION_SCHEMA.columns 
where table_schema = 'so_gibberish' -- your database/schema name 
and table_name='tableA' 


+--------------+------------+-----------------------+------------------+-------------+-----------+--------------------+----------------+--------------------------+------------+----------------+ 
| table_schema | table_name | column_name   | ordinal_position | is_nullable | data_type | character_set_name | collation_name | column_type    | column_key | extra   | 
+--------------+------------+-----------------------+------------------+-------------+-----------+--------------------+----------------+--------------------------+------------+----------------+ 
| so_gibberish | tablea  | id     |    1 | NO   | int  | NULL    | NULL   | int(11)     | PRI  | auto_increment | 
| so_gibberish | tablea  | w      |    2 | NO   | int  | NULL    | NULL   | int(8) unsigned zerofill |   |    | 
| so_gibberish | tablea  | x      |    3 | NO   | int  | NULL    | NULL   | int(8)     |   |    | 
| so_gibberish | tablea  | y      |    4 | NO   | int  | NULL    | NULL   | int(11)     |   |    | 
| so_gibberish | tablea  | z      |    5 | NO   | int  | NULL    | NULL   | int(10) unsigned   |   |    | 
| so_gibberish | tablea  | shortBinaryCharString |    6 | NO   | char  | utf8    | utf8_bin  | char(10)     |   |    | 
| so_gibberish | tablea  | myBlob    |    7 | YES   | blob  | NULL    | NULL   | blob      |   |    | 
+--------------+------------+-----------------------+------------------+-------------+-----------+--------------------+----------------+--------------------------+------------+----------------+ 

您还可能有运气与执行

SHOW FIELDS FROM tableA;

show create table tableA

用标准的Java结果集,你最有可能已经在这样做就足够了。

try { 
     con = DriverManager.getConnection(url, user, password); 
     st = con.createStatement(); 
     rs = st.executeQuery("show fields from tableA"); 
     while (rs.next()) { 
      System.out.println(rs.getString(1)+": "+rs.getString(2)); 
} catch (SQLException ex) { 
    Logger lgr = Logger.getLogger(myTest.class.getName()); 
    lgr.log(Level.SEVERE, ex.getMessage(), ex); 
} 

注:字符集,并显示出对比检验列的原因在于,存在具有与某个字符集排序顺序炭二进制列之间的细微差别的差别。与没有二进制排序顺序的真正二进制blob/text列相比。请参阅标题为The BINARY and VARBINARY Types的Mysql手册页,并确定它如何适用于“二元”概念。通常,必须解析一列输出以确定是否打开zerofill。