ibatis 查询结果没有返回

pengpeng11 2009-09-29 09:52:10
在进行条件查询时,没有查出数据库中的该记录,感觉可能是传参数的问题,有点奇怪,请哪位兄弟帮我看下

<select id="getBlackList" parameterClass="String" resultClass="BlackList">
select * from black_list where phone_number=#phoneNumber# //字符串参数也应该是这样传的,可就是查不出
</select>



下面是java 中的调用代码:

@Test
public void t()
{
BlackList bl = new BlackList();

bl = DaoFactory.getBlackListDaoInstance().findByNumber("150");

System.out.println(bl.getListId()); //取得查出的该条记录的id,可就查不出,查出的结果是0,数据库中有该记录的
}


下是log4j打印出的:

2009-09-29 09:37:37,875 DEBUG

[com.ibatis.common.jdbc.SimpleDataSource] - Created connection

30936685.
2009-09-29 09:37:37,906 DEBUG [java.sql.Connection] - {conn-100000}

Connection
2009-09-29 09:37:37,906 DEBUG [java.sql.Connection] - {conn-100000}

Preparing Statement: select * from black_list where phone_number=?
2009-09-29 09:37:38,000 DEBUG [java.sql.PreparedStatement] - {pstm-

100001} Executing Statement: select * from black_list where phone_number=?
2009-09-29 09:37:38,000 DEBUG [java.sql.PreparedStatement] - {pstm-100001} Parameters: [150]
2009-09-29 09:37:38,000 DEBUG [java.sql.PreparedStatement] - {pstm-100001} Types: [java.lang.String]
2009-09-29 09:37:38,000 DEBUG [java.sql.ResultSet] - {rset-100002}

ResultSet2009-09-29 09:37:38,046 DEBUG

[com.ibatis.common.jdbc.SimpleDataSource] - Returned connection 30936685 to pool.
...全文
154 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
snow_online 2009-09-29
  • 打赏
  • 举报
回复
<select id="getBlackList" parameterClass="String" resultClass="BlackList">
select * from black_list where phone_number=#phoneNumber# //字符串参数也应该是这样传的,可就是查不出
</select>


resultClass 不应该是BlackList把
pengpeng11 2009-09-29
  • 打赏
  • 举报
回复
按4楼那办法能查出了,但我在xml中配置了数据库字段和属性间的映射关系啊,直接查的话怎么查不到

<resultMap id="BlackListResult" class="BlackList">
<result property="listId" column="list_id"/>
<result property="phoneNumber" column="phone_number"/>
<result property="numberType" column="number_type"/>
</resultMap>
snow_online 2009-09-29
  • 打赏
  • 举报
回复
你的数据库表 black_list 字段listId 跟pojo类的listId是一致的吗?

select
listid as listId,
phoneNumber as phoneNumber,
numberType as numberType

from
black_list where phone_number=#phoneNumber#

推荐这样写
pengpeng11 2009-09-29
  • 打赏
  • 举报
回复
BlackList 实体类:

private static final long serialVersionUID = 6218562431438580204L;

private long listId; //名单id
private String phoneNumber ; //手机号
private String numberType ; //手机号所属的类别

public long getListId() {
return listId;
}
public void setListId(long listId) {
this.listId = listId;
}

public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getNumberType() {
return numberType;
}
public void setNumberType(String numberType) {
this.numberType = numberType;
}


DAO中查询的方法:

public BlackList findByNumber(String phoneNumber) {
BlackList bl = null;

try {

bl = (BlackList)sqlMap.queryForObject("getBlackList", phoneNumber);
}catch(SQLException e){
e.printStackTrace();
}
return bl;
}


freefly2005 2009-09-29
  • 打赏
  • 举报
回复
DAO也贴出来嘛 还有你的BlackList里面的代码也贴出来嘛
pengpeng11 2009-09-29
  • 打赏
  • 举报
回复
诸位帮忙看下啊,多谢

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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