天天看點

資料集操作

代碼運作報錯:

----------> Parent Classloader:
java.net.URLClassLoader@1c53fd30
:
java.lang.ClassNotFoundException: org.springframework.dao.TransientDataAccessResourceException
八月 10, 2018 5:45:28 下午 com.caucho.hessian.io.SerializerFactory getDeserializer
警告: Hessian/Burlap: 'org.springframework.dao.TransientDataAccessResourceException' is an unknown class in ParallelWebappClassLoader
  context: cc-web
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@1c53fd30
:
java.lang.ClassNotFoundException: org.springframework.dao.TransientDataAccessResourceException
com.weibo.api.motan.exception.MotanServiceException: error_message: biz exception cause is throwable error:class java.lang.Throwable, errmsg:PreparedStatementCallback; SQL [SELECT `free_pricing` FROM `account` WHERE `account_id`=?]; Before start of result set, status: 503, error_code: 10001,r=null
	at com.weibo.api.motan.proxy.RefererInvocationHandler.invoke(RefererInvocationHandler.java:127)
	at com.sun.proxy.$Proxy71.getFreePricingStatus(Unknown Source)
	at com.btzh.resource.ProfileResource.toCopyright(ProfileResource.java:285)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)           

代碼是很簡單的一個sql查詢:

@Override
	public YesOrNo getFreePricingStatus(Integer accountId) {
		return jdbcTemplate.query("SELECT `free_pricing` FROM `account` WHERE `account_id`=?", new Object[] { accountId }, new ResultSetExtractor<YesOrNo>() {
			@Override
			public YesOrNo extractData(ResultSet rs) throws SQLException, DataAccessException {
				return YesOrNo.getByValue(rs.getInt("free_pricing"));
			}
		});
	}           

單元測試沒有任何問題, 放到項目中運作就出現上面的報錯. 後來想是不是因為缺少rs.next(), 導緻指針仍然在第一個元素的前一個位置, 導緻指針沒有下移, 改了下:

@Override
	public YesOrNo getFreePricingStatus(Integer accountId) {
		return jdbcTemplate.query("SELECT `free_pricing` FROM `account` WHERE `account_id`=?", new Object[] { accountId }, new ResultSetExtractor<YesOrNo>() {
			@Override
			public YesOrNo extractData(ResultSet rs) throws SQLException, DataAccessException {
				if (rs.next()) {
					return YesOrNo.getByValue(rs.getInt("free_pricing"));
				}
				return YesOrNo.NO;
			}
		});
	}           

好了. 但是沒想清楚為什麼單元測試沒有報錯, 待續.