锁定老帖子 主题:问个IBATIS的插入问题
该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2006-10-17
STRUTS跟SPRING已经配置OK了,就是调用IBATIS时..数据不插入到数据库. ====================================================== USER.XML配置如下: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd"> <sqlMap namespace="User"> <typeAlias alias="user" type="net.baizhan.demo.data.bo.User" /> <insert id="insertUser" parameterClass="user">INSERT INTO demo (username, password) VALUES ( #username#, #password# )</insert> </sqlMap> ======================================================= USERDAO的代码如下: package net.baizhan.demo.data.dao; import net.baizhan.demo.data.bo.User; import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; public class UserDAO extends SqlMapClientDaoSupport implements IUserDAO { public boolean Insert(User user) { // TODO Auto-generated method stub getSqlMapClientTemplate().insert("insertUser",user); return true; } } ====================================================== 望各位下小弟,小弟刚开始学IBATIS的...先谢谢了... 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2006-10-17
1 getSqlMapClientTemplate().insert("User.insertUser",user);
2 USER.XML 确认导入没 |
|
返回顶楼 | |
发表时间:2006-10-17
如果没导入的话应该会有异常吧
select语句正常么?? |
|
返回顶楼 | |
发表时间:2006-10-17
ddandyy 写道 如果没导入的话应该会有异常吧
select语句正常么?? 没有异常啊 SERVICE代码 ================================================ package net.baizhan.demo.model.service; import net.baizhan.demo.data.bo.User; import net.baizhan.demo.data.dao.IUserDAO; public class UserService implements IUserService { private IUserDAO userDAO; public boolean Insert(User user) { // TODO Auto-generated method stub try{ userDAO.Insert(user); return true; }catch(RuntimeException e){ return false; } } public IUserDAO getUserDAO() { return userDAO; } public void setUserDAO(IUserDAO userDAO) { this.userDAO = userDAO; } } ================================================= Ibatis的配置信息 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"> <value>net.sourceforge.jtds.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:jtds:sqlserver://localhost/mytest</value> </property> <property name="username"> <value>sa</value> </property> <property name="password"> <value></value> </property> </bean> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation"> <value>/WEB-INF/SqlMapConfig.xml</value> </property> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource"> <ref local="dataSource" /> </property> </bean> <bean id="userDAO" class="net.baizhan.demo.data.dao.UserDAO"> <property name="dataSource"> <ref local="dataSource" /> </property> <property name="sqlMapClient"> <ref local="sqlMapClient" /> </property> </bean> <bean id="userDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"> <ref bean="transactionManager" /> </property> <property name="target"> <ref local="userDAO" /> </property> <property name="transactionAttributes"> <props> <prop key="insert*">PROPAGATION_REQUIRED</prop> <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> </bean> </beans> ======================================================== Service的配置 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="UserService" class="net.baizhan.demo.model.service.UserService"> <property name="userDAO"> <ref bean="userDAOProxy" /> </property> </bean> </beans> ======================================================= SQL的映射配置 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd"> <sqlMapConfig> <sqlMap resource="net/baizhan/demo/data/bo/User.xml" /> </sqlMapConfig> ===================================================== View配置 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean name="/login" class="net.baizhan.demo.view.struts.action.LoginAction" singleton="false"> <property name="userService"> <ref bean="UserService" /> </property> </bean> </beans> |
|
返回顶楼 | |
发表时间:2006-10-18
自己顶啊..希望高手能帮忙解答一下....程序没有出错..就是不会将数据插入数据库啊...
另外如何让IBATIS能够显示SQL语句(在运行时) |
|
返回顶楼 | |
发表时间:2006-10-18
log4j.rootLogger=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG 这样会显示SQL |
|
返回顶楼 | |
发表时间:2006-10-18
oldpig 写道 log4j.rootLogger=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG 这样会显示SQL 谢谢...偶试看看....做个简单的插入都插不到数据库... |
|
返回顶楼 | |
发表时间:2006-10-18
ibatis最好的特性,你给忽略了,就是SQL可以直接提取到命令行执行或plsql里!
|
|
返回顶楼 | |
发表时间:2006-10-18
study
|
|
返回顶楼 | |
发表时间:2006-10-19
galaxystar 写道 ibatis最好的特性,你给忽略了,就是SQL可以直接提取到命令行执行或plsql里!
这个偶不懂啊..刚学习..不知道这个高手有没有DEMO拿一个来学习学习.. |
|
返回顶楼 | |