亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

java - Mybatis查詢資料庫(kù)時(shí)出現(xiàn)查詢getInt()??的錯(cuò)誤
ringa_lee
ringa_lee 2017-04-18 10:56:22
0
1
1067

我數(shù)據(jù)庫(kù)表的id是varchar類型,而已這條數(shù)據(jù)也是項(xiàng)目插入到數(shù)據(jù)庫(kù)的,但是在後麵查詢的時(shí)候就出現(xiàn)了一下錯(cuò)誤。

嚴(yán)重: Servlet.service() for servlet [SpringMVC] in context with path [/cims-ssm] threw exception [Request processing failed; nested exception is org.springframework.dao.TransientDataAccessResourceException: Error attempting to get column 'id' from result set.  Cause: java.sql.SQLException: Invalid value for getInt() - 'x41D6z93'
; SQL []; Invalid value for getInt() - 'x41D6z93'; nested exception is java.sql.SQLException: Invalid value for getInt() - 'x41D6z93'] with root cause
java.sql.SQLException: Invalid value for getInt() - 'x41D6z93'

這是錯(cuò)誤信息,以下是相關(guān)代碼


這是查詢映射代碼

我代碼在數(shù)據(jù)庫(kù)裏就能查詢出來(lái)

望各位看看
對(duì)了 model中 club中的id屬性是string的

ringa_lee
ringa_lee

ringa_lee

全部回覆(1)
巴扎黑

mapping的問(wèn)題:

<resultMap id="resultClubType" type="com.uiyllong.cims.model.ClubType">
    <id column="id" jdbcType="INTEGER" property="id" />
    <!-- 省略 -->
</resultMap>
<resultMap id="resultClub" type="com.uiyllong.cims.model.Club">
    <id column="id" jdbcType="VARCHAR" property="id" />
    <!-- 省略 -->
    <association column="club_type_id" jdbcType="INTEGER"
        property="clubType" javaType="com.uiyllong.cims.model.ClubType"
        resultMap="resultClubType" />
</resultMap>

resultClub和resultClubType的id屬性對(duì)應(yīng)的列名都是id,而其中一個(gè)的型別是int。

sql的問(wèn)題(記得以後貼問(wèn)題把程式碼貼上來(lái),貼截圖讓人家怎麼拿你程式碼試,手敲嗎?):

select club_t.id, ...
club_type_t.id
....

這個(gè)查詢結(jié)果有兩列ID

解決方法很簡(jiǎn)單,把 club_type_t 欄位設(shè)定別名,例如加上前綴:

select club_t.id, ...
club_type_t.id ct_id, club_type_t.typeName ct_type_name

利用mybatis的columnPrefix:

<association property="clubType" 
  columnPrefix="ct_"
  notNullColumn="ct_id"
  resultMap="resultClubType" />
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板