Mysql中如何获取一条数据中所有字段的名称和值

有一个表User, 有字段id, name, password, mobile.
现在要获取User表中id=1的所有字段的名称保存为'key',其对应的值为'value'

例如有表中一条记录:
id name password mobile
1 test 123 138100138000

现在要获取这一条记录并保存为

key value
id 1
name test
password 123
mobile 13800138000

select * from User

一种使用jdbc的metadata,另一种是通过 select * from columns where table_name='表名'; 查询表结构

select * from 表 where id="1"

用navicat可视化就可以看到咯,用sql的话,select*就可以啦

使用jdbc的metadata方法吧,还不错

select COLUMN_NAME from information_schema.columns t where TABLE_NAME='表名';