java - JDBC PreparedStatement with aggregate function on dynamic column in Select clause -
i trying come utility can max of data length in each column of table.
- i have list of columns in list.
- i go on each list.
execute below prepared statement.
string sql = "select max(datalength(?)) positions"; for(iterate on list of column names) { preparedstatement.setstring(1, stringutils.trim(columnname)); resultset rs = preparedstatement.executequery(); if (rs.next()) { int length1 = rs.getint(1); //print column name , max data length } }
seems prepared statement max function taking dynamic column not working. gives incorrect values.
can prepared statement work dynamic column in select clause.
using prepared statement can this. believe if requirement comes there may issue in db design.
if still want continue approach can create sql string own :
string sql = "select max(datalength("+ columnname +")) positions"
or: can use `string#.replace().
but not approach & may sql injection can occurred.
Comments
Post a Comment