使用准备好的语句进行选择查询时出现 SQL 异常
StringBuilder sqlQry = new StringBuilder();
sqlQry.append("SELECT LIB, PATH")
.append(" FROM OBJ")
.append(" INNER JOIN SRC ON SRC.MBR = OBJ.LOBJ")
.append(" WHERE TYPE = '*PGM'")
.append(" AND SRC.PATH LIKE '").append("?").append("%'");
PreparedStatement ps = accssConn.prepareStatement(sqlQry.toString());
ps.setString(1, path);
rs = ps.executeQuery();
大家好,我收到以下异常
Hi All, I am getting following exception
[jcc][10145][10844][3.63.123] Invalid parameter 1: Parameter index is out of range. ERRORCODE=-4461, SQLSTATE=42815
列限制为 255,路径为 = "C:Documents and SettingsxyzDesktopxyzs" 并且在语句中运行良好.那么,它在准备好的语句中抛出异常的原因是什么.
column limit is 255 and path is = "C:Documents and SettingsxyzDesktopxyzs" and it is run fine with statement.So , what is the reason that it is throwing exception in prepared statement.
推荐答案
StringBuilder sqlQry = new StringBuilder();
sqlQry.append("SELECT LIB, PATH")
.append(" FROM OBJ")
.append(" INNER JOIN SRC ON SRC.MBR = OBJ.LOBJ")
.append(" WHERE TYPE = '*PGM'")
.append(" AND SRC.PATH LIKE ").append("?");
PreparedStatement ps = accssConn.prepareStatement(sqlQry.toString());
ps.setString(1, path + "%");
相关文章