我想要返回 row_number 按变量模型类:
而示例中的PreparedStatament是我探索的,rferencia是列名称。 row_number 不是表的 native 列或物理列。如何使 dete 方法的值像实际的物理表列一样返回。在表中创建一个新列来存储这些值也没有什么意义。我也不打算使用触发器来返回这些值。可以这样完成,下面的代码不会出现错误。
final StringBuffer lSql = new StringBuffer();
lSql.append("SELECT ");
lSql.append(" TABLE_NAME.ROW_NUMBER() OVER (ORDER BY COLUMN_DAY) ");
lSql.append("FROM ...");
// ...
final List<classModel> listData = new ArrayList<classModel>();
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rset = null;
try{
conn = getConnection1();
stmt = conn.prepareStatement(lSql.toString());
int count = 1;
//stmt.setLong(count++, classModelParameterThisFunctionDAO.getVarColumnSequence());
//...
rset = stmt.executeQuery(); // ERROR THIS LINE NI DEBUG
while(rset.nex()){
final classModel lClassModel = new classModel();
lClassModel.setColumnSequence(rset.getInt("ROW_NUMBER() OVER (ORDER BY COLUMN_DAY)")); //error in this line
listData.add(lClassModel);
最佳答案
lSql.append("SELECT ");
lSql.append(" TABLE_NAME.ROW_NUMBER() OVER (ORDER BY COLUMN_DAY) as RRN ");
lSql.append("FROM ...")
.
.
.
lClassModel.setColumnSequence(rset.getInt("RRN"));
关于java - 如何在Java中使用准备好的语句和StringBuffer返回row_number,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32632655/