4
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();

大家好,我收到以下异常

[jcc][10145][10844][3.63.123] Invalid parameter 1: Parameter index is out of range. ERRORCODE=-4461, SQLSTATE=42815

列限制为 255,路径为 = "C:\Documents and Settings\xyz\Desktop\xyzs" 并且在语句中运行良好。那么,它在准备好的语句中抛出异常的原因是什么。

4

2 回答 2

3
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 + "%");
于 2012-09-13T05:45:33.770 回答
0

检查您的单引号,我认为其中一个缺少结束引号。还可以尝试将单引号更改为双引号并像 \"*PGM\" 一样转义它们

于 2012-09-13T06:42:15.033 回答