String sql="SELECT a.USER_ID from FTE_USER a where a.USERNAME=? AND a.CELLPHONE=?";
Integer count=0;
Object[] parm = { userName, cellPhone };
System.out.println("SELECT a.USER_ID from FTE_USER a where a.USERNAME='"+userName+"' AND a.CELLPHONE='"+cellPhone+"'");
try {
count= this.baseSpringJdbcDAO.getJdbcTemplate().queryForInt(sql, parm);
System.out.println(count);
} catch (Exception ex) {
ex.printStackTrace();
count= -1;
}
return count;
Integer count=0;
Object[] parm = { userName, cellPhone };
System.out.println("SELECT a.USER_ID from FTE_USER a where a.USERNAME='"+userName+"' AND a.CELLPHONE='"+cellPhone+"'");
try {
count= this.baseSpringJdbcDAO.getJdbcTemplate().queryForInt(sql, parm);
System.out.println(count);
} catch (Exception ex) {
ex.printStackTrace();
count= -1;
}
return count;
解决方案 »
- 3000分求JSP图片上传/放大缩小/裁减的源代码
- 在eclipse下不能用javabean
- 刷新页面,出现这个“提示“不重新发送信息,则无法刷新网页。请单击"重试"再次发送信息,或单击"取消"返回正查看的页.“请问如何改”
- 跪求struts如何防止重复提交的答案
- 又是一个关于enctype="MULTIPART/FORM-DATA"的问题
- 救命啊!第一个servlet的例子没法显示
- 一个很不错的上传类,大家顶一把!
- 对于网站的日志管理有源码可下载的吗?
- 我下载了JBOSS3,解包后,不知道怎么用,我的JSP文件应该放在哪里?
- 请教高手,SERVLET的烦恼
- request.getParameter()获取不到值啊
- 人力管理系统登陆问题
但是要是不存在的话就运行到ex.printStackTrace();抛出异常了,怎么解决呢?
你的sql中虽然user_id是number类型,但是实际是返回一个结果集(不管最终是否是一条记录),也就是一个List
所以你这种场景只能用
List<Map<String, Object>> rows = this.baseSpringJdbcDAO.getJdbcTemplate().query(sql, parm);
//处理results,取第一条记录
if (null != rows && !rows.isEmpty()) {
Map<String, Object> row = rows.get(0);
System.out.println(row.get("USER_ID"));
}
List rows = this.baseSpringJdbcDAO.getJdbcTemplate().queryForList(sql, parm);
if (null != rows && rows.size()>0) {
count=Integer.parseInt(rows.get(0).toString());
}
这个还不知道行不行呢?
他是有异常,但是没关系,抛出来就行了
就是下面:
catch(EmptyResultDataAccessException e){
return 0;
}