gpt4 book ai didi

java - 使用准备好的语句进行选择查询时获取 SQL 异常

转载 作者:搜寻专家 更新时间:2023-11-01 03:10:14 25 4
gpt4 key购买 nike

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"并且语句运行良好。那么,它在准备好的语句中抛出异常的原因是什么。

最佳答案

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

关于java - 使用准备好的语句进行选择查询时获取 SQL 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12399879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com