java.lang.StringIndexOutOfBoundsException: String index out of range: 9

AbuCoder 2019-03-03 08:42:25
今天在做练习时遇到一个问题一直解决不了,请各位大佬帮忙解决。谢谢!
批量更新时老师报这个异常,我输出看了下到第590时就抛出异常导致后续无法继续。不知道怎么解决了。我也查不到原因了,望大家帮忙看看!

抛出的异常:
590:530629202
java.lang.StringIndexOutOfBoundsException: String index out of range: 9
at java.lang.String.substring(String.java:1963)
at com.justep.yn.jyt.base.UpdateBaseAreaPuid.dataUpdate(UpdateBaseAreaPuid.java:63)
at com.justep.yn.jyt.base.UpdateBaseAreaPuid.main(UpdateBaseAreaPuid.java:18)
代码如下:
public static void dataUpdate() throws SQLException {
String quary = "select FID,fQUYUBIANHAO from XX WHERE fLEIXING='乡镇'";// 查询
List<Map<String, String>> quqrylist = DBUtils.execQueryforList("oa", quary);
Connection conn = null;
PreparedStatement ps = null;
try {
conn = DBUtils.getAppConn("oa");
for (int i = 0; i < quqrylist.size(); i++) {
int q=i++;
String no=quqrylist.get(i).get("fQUYUBIANHAO").substring(0, 9);
String ffid=quqrylist.get(i).get("FID");
ps = conn.prepareStatement("update XX SET fFUID='"+ffid+"' WHERE fLEIXING='村' AND SUBSTRING(fQUYUBIANHAO, 1, 9) = '"+no+"'");
ps.executeUpdate();
System.out.println(q+":"+no);
}
} catch (Exception e) {
e.printStackTrace();
}finally {
DBUtils.CloseConn(conn, ps, null);
}
}

}
...全文
819 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
程序袁_哈哈 2019-03-11
  • 打赏
  • 举报
回复
你可以在substring之前,先判断下str的长度, 把长度小于10的打印出来看看就知道了。
沁海棠 2019-03-09
  • 打赏
  • 举报
回复
每个map里用fQ... 做键取值,你确定map中对应的value 长度都够么。加个判断吧。
zz90zz 2019-03-04
  • 打赏
  • 举报
回复
不会用DEBUG看一下处理的数据么?
AbuCoder 2019-03-04
  • 打赏
  • 举报
回复
有12位数的,substring的时候 有字符串长度没有到9??这个我也想过,但是还是不知道怎么回事
  • 打赏
  • 举报
回复
越界异常,好像是不够
汤姆猫来啦 2019-03-03
  • 打赏
  • 举报
回复
看看 execqueryforlist方法
汤姆猫来啦 2019-03-03
  • 打赏
  • 举报
回复
substring的时候 有字符串长度没有到9
这是一个维护版本,主要是bug修复: ** Bug * [MNG-4840] - Prerequisites is not working on m3 * [MNG-4913] - [regression] User properties override equally named POM properties of transitive dependencies * [MNG-4915] - Versions in pom.xml are not checked for invalid characters * [MNG-4918] - MavenProject#clone() doubles active profiles * [MNG-4919] - Plugin execution contributed by lifecycle mapping gets lost when same goal is bound multiple times * [MNG-4923] - [regression] java.lang.ClassNotFoundException: org.apache.maven.artifact.ArtifactStatus * [MNG-4925] - Mismanagement of container lookup realm can cause type incompatibilities for plugins looking up components by string * [MNG-4933] - With a resource directory as . maven raise an java.lang.StringIndexOutOfBoundsException:217 * [MNG-4941] - PluginDescriptorBuilder doesn't populate expression/default-value fields for mojo parameters * [MNG-4952] - [regression] RELEASE field of repository metadata is not updated upon repeated deployments * [MNG-4955] - [regression] Outdated remote snapshots are preferred over locally installed snapshots * [MNG-4960] - [regression] Make-like reactor mode does not build selected project when resuming from one of its prerequisites * [MNG-4966] - Preserve double slashes in the scm connection url - identifies absolute repository paths for mercurial ** Improvement * [MNG-4912] - Use of raw type should be Comparable * [MNG-4916] - Poor ProjectBuilder.build performance for projects with unresolvable extension plugins * [MNG-4922] - ExecutionEvent give on the exception encountered (when having mojoFailed) * [MNG-4926] - ExecutionEvent give on the exception encountered (when having projectFailed , forkedProjectFailed) * [MNG-4944] - Include JRE vendor in version info * [MNG-4950] - Javadoc improvements to DefaultSettingsWriter/Reader * [MNG-4953] - Issue a warning when a system-scope dependency refers to the project basedir ** New Feature * [MNG-4936] - Allow to better monitor and adjust a Maven build during CI * [MNG-4937] - Allow the platform scripts to avoid loading mavenrc content ** Task * [MNG-4945] - Remove mergeId from public POM * [MNG-4957] - Emit validation warning when project version uses irregular SNAPSHOT version string * [MNG-4959] - Update default plugin versions

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧