是否可以使用行号和列号进行 SQL 更新? [英] Is it possible to SQL Update using row and column numbers?

查看:36
本文介绍了是否可以使用行号和列号进行 SQL 更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jquery datables/jedtiable,它传回 ROW 和 COLUMN 编号以及要更新的新值,如下所示.这是 POST 到另一个 JSP 页面,该页面具有到 sqlite 数据库的 JDBC 连接.

I am using jquery datables/jedtiable which passed back ROW and COLUMN number and new VALUE to be updated like below. This is POST'ed to another JSP page which has a JDBC connection to an sqlite DB.

注意:我不想指定列名,只是一个基于从我的其他页面发布的 int 的数字.希望这能让我的问题更清楚

NOTE: I don't want to specify the column name, Just a number based on the int POST'ed from my other page. Hopefully this makes my question clearer

行、值、列

2 没有 4

将No"更新到第 2 行第 4 列的 SQL 是什么?

What is the SQL to update 'No' into row 2 column 4?

更新*********

Update *********

目前正在使用 rowid,但我仍然希望能够按数字使用列.

This is currently working with rowid, however I would still like to be able to use column by number.

     String value = request.getParameter("value");
     String row = request.getParameter("row_id");
     String column = request.getParameter("column");

UPDATE PROJECT SET DELIVERY_STREAM ='"+value+"' WHERE rowid = "+rowId+";

推荐答案

所有 SQL 命令都需要列名称,而不是数字.

All SQL commands require column names, not numbers.

此外,SQL 表没有行号有意义的固有顺序;记录只能通过一些唯一的字段值来标识.

Furthermore, SQL tables do not have an inherent order where row numbers would make sense; records can be identified only by some unique field values.

所以,严格来说,你的问题的答案是不".

So, strictly speaking, the answer to your question is "no".

要按编号访问列,您需要知道哪个列有哪个编号,以便将编号映射回相应的名称:

To access columns by number, you need to know which column has which number so that you can map the number back to the corresponding name:

String[] columnNames = new String[] {
    "NAME", "DELIVERY_STREAM", "NUMBER_OF_FEET", "RETICULATED", ...
};
int columnNumber = ...;

String sql = "UPDATE Project SET " + columnNames[columnNumber] + " = ? WHERE ...";

从行号到实际记录的映射需要您将包含这些记录的键值的数组存储在某处,但这在使用多个 JSP 页面时是不可行的.而不是行号,只需使用原始表中的一些键值(主键,或 SQLite 的 rowid)来识别记录;这就是钥匙的用途.

Mapping from row numbers to actual records would require that you store an array with those records' key values somewhere, but this is not feasible when using multiple JSP pages. Instead of the row number, just use some key value from the original table (the primary key, or SQLite's rowid) to identify records; that is what keys are for.

这篇关于是否可以使用行号和列号进行 SQL 更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆