当前位置: 技术问答>java相关
我想对选中的记录进行修改,不知道怎么能得到我所选中行的主键。谢谢!
来源: 互联网 发布时间:2017-03-27
本文导语: 我想对选中的记录进行修改,不知道怎么能得到我所选中行的主键。谢谢! | “行的主键”应该没有这么怪的说法,表的主键吧? 首先你要知道这些记录是哪个表的嘛。 知道了表名,得到表...
我想对选中的记录进行修改,不知道怎么能得到我所选中行的主键。谢谢!
|
“行的主键”应该没有这么怪的说法,表的主键吧?
首先你要知道这些记录是哪个表的嘛。
知道了表名,得到表的主键就好办了:
通过connection.getMetaData()得到数据库描述对象:DatabaseMetaData。
然后用:DatabaseMetaData.getPrimaryKeys方法就可以了。
public ResultSet getPrimaryKeys(String catalog,
String schema,
String table)
throws SQLException
Retrieves a description of the given table's primary key columns. They are ordered by COLUMN_NAME.
Each primary key column description has the following columns:
TABLE_CAT String => table catalog (may be null)
TABLE_SCHEM String => table schema (may be null)
TABLE_NAME String => table name
COLUMN_NAME String => column name
KEY_SEQ short => sequence number within primary key
PK_NAME String => primary key name (may be null)
Parameters:
catalog - a catalog name; must match the catalog name as it is stored in the database; "" retrieves those without a catalog; null means that the catalog name should not be used to narrow the search
schema - a schema name; must match the schema name as it is stored in the database; "" retrieves those without a schema; null means that the schema name should not be used to narrow the search
table - a table name; must match the table name as it is stored in the database
Returns:
ResultSet - each row is a primary key column description
Throws:
SQLException - if a database access error occurs
首先你要知道这些记录是哪个表的嘛。
知道了表名,得到表的主键就好办了:
通过connection.getMetaData()得到数据库描述对象:DatabaseMetaData。
然后用:DatabaseMetaData.getPrimaryKeys方法就可以了。
public ResultSet getPrimaryKeys(String catalog,
String schema,
String table)
throws SQLException
Retrieves a description of the given table's primary key columns. They are ordered by COLUMN_NAME.
Each primary key column description has the following columns:
TABLE_CAT String => table catalog (may be null)
TABLE_SCHEM String => table schema (may be null)
TABLE_NAME String => table name
COLUMN_NAME String => column name
KEY_SEQ short => sequence number within primary key
PK_NAME String => primary key name (may be null)
Parameters:
catalog - a catalog name; must match the catalog name as it is stored in the database; "" retrieves those without a catalog; null means that the catalog name should not be used to narrow the search
schema - a schema name; must match the schema name as it is stored in the database; "" retrieves those without a schema; null means that the schema name should not be used to narrow the search
table - a table name; must match the table name as it is stored in the database
Returns:
ResultSet - each row is a primary key column description
Throws:
SQLException - if a database access error occurs
|
用复选框,复选框的值就是所对应记录的唯一标识,就是这张表的主键在该行记录的值,这样香山处级行都可以。