简体   繁体   中英

How return row_number use prepared Statement with StringBuffer in Java

I want the return row_number press the Variable Model class:

Whereas the PreparedStatament in the examples I exploreri, rferencia the column name. row_number is not a native or physical column of the table. How to make the values dete method are returned as if they were an actual physical table column. Nor would it be interesting to create a new column in the table to just store these values. I also do not intend to use triggers to return these values. It can be done this way is without error in the code below.

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"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM