英文:
insert into existing row/select non-empty fields
问题
https://i.stack.imgur.com/zu1MR.png
大家好,如图所示,在图片中有许多空字段,这是插入数据(左下角)只在单列下进行的结果。这既不美观,也不太清晰。
我的第一个问题是,在插入数据时,是否可以将数据插入到最后一条数据的正下方,而不是作为全新的一行?
其次,在java应用程序中在查询/设置模型(query/setModel())中使用SELECT时,是否可以仅检索非空字段?
获取数据的代码:
public void showExports(){
table.setModel(DbUtils.resultSetToTableModel(getResultSet("select * from t1")));}
插入数据的代码:
insert into t1 (`68`) values ('01/04/2020')
编辑:
表格类似于这样:
(由于站点不接受更多的空格,我将使用“-”来使其更清晰)
11---------------14-------------31----------------53------------68(列标题)
01/04/2020
-----------03/04/2020
------------------------------------------------02/04/2020
---------------------------05/04/2020
--------------------------------------------------------------01/04/2020
(日期位于列名称下方)
英文:
https://i.stack.imgur.com/zu1MR.png
h i all, as you can see on the picture there is lot of empty fields as result of inserting data (left bottom) only under single column. it is not nice neither very clear
my first question is, while inserting, can i somehow insert that data right under the last data and not as whole new row?
secondly, while using SELECT in query/setModel() in java app is it possible to retrieve just non-empty fields?
code to get data:
public void showExports(){
table.setModel(DbUtils.resultSetToTableModel(getResultSet("select * from t1")));}
code to insert:
insert into t1 (`68`) values ('01/04/2020')
edit:
table is something like this:
(site doesn't accept more spaces so i'll use "-" so it is more clear)
11---------------14-------------31----------------53------------68 (column headers)
01/04/2020
-----------03/04/2020
------------------------------------------------02/04/2020
---------------------------05/04/2020
--------------------------------------------------------------01/04/2020
(dates are under column names)
答案1
得分: 0
你需要一个“更新”操作。类似这样:
update t1
set `68` = '2020-04-01' -- 注意正确的日期格式
where . . . ;
其中的 where
子句是用于指定逻辑,以确定你所说的“最后一行”。通常,这可能类似于 id = ?
,其中 ?
是一个参数,用于指定最近插入行的 id。
英文:
You want an update
. Something like this:
update t1
set `68` = '2020-04-01' -- note correct date format
where . . . ;
The where
is for the logic that specifies what you mean by "last row". Typically, this would be something like id = ?
, where ?
is a parameter to specify the id of the most recently inserted row.
专注分享java语言的经验与见解,让所有开发者获益!
评论