java自定义类中,基本的增删改查代码 50
5个回答
展开全部
用java的反射机制可以做对数据库中表的增删改查。不过没什么意义,练下技术还可以。最简单的就是hibernate,它里面已经全部封装好了方法,只需调个方法就可以了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
请先自学JDBC 完成增删改查代码 再学习servlet. 再学习struts 在学习hibernate 在学习 spring
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
请自己学习hibernante
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public void save(AnswerInfo transientInstance) {
log.debug("saving AnswerInfo instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(AnswerInfo persistentInstance) {
log.debug("deleting AnswerInfo instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public AnswerInfo findById(java.lang.Integer id) {
log.debug("getting AnswerInfo instance with id: " + id);
try {
AnswerInfo instance = (AnswerInfo) getHibernateTemplate().get(
"com.wj.po.AnswerInfo", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(AnswerInfo instance) {
log.debug("finding AnswerInfo instance by example");
try {
List results = getHibernateTemplate().findByExample(instance);
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding AnswerInfo instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from AnswerInfo as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findByDoctorname(Object doctorname) {
return findByProperty(DOCTORNAME, doctorname);
}
public List findByContent(Object content) {
return findByProperty(CONTENT, content);
}
public List findByAnswerTimes(Object answerTimes) {
return findByProperty(ANSWER_TIMES, answerTimes);
}
public List findAll() {
log.debug("finding all AnswerInfo instances");
try {
String queryString = "from AnswerInfo";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public AnswerInfo merge(AnswerInfo detachedInstance) {
log.debug("merging AnswerInfo instance");
try {
AnswerInfo result = (AnswerInfo) getHibernateTemplate().merge(
detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(AnswerInfo instance) {
log.debug("attaching dirty AnswerInfo instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(AnswerInfo instance) {
log.debug("attaching clean AnswerInfo instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static AnswerInfoDAO getFromApplicationContext(ApplicationContext ctx) {
return (AnswerInfoDAO) ctx.getBean("AnswerInfoDAO");
}
}
log.debug("saving AnswerInfo instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(AnswerInfo persistentInstance) {
log.debug("deleting AnswerInfo instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public AnswerInfo findById(java.lang.Integer id) {
log.debug("getting AnswerInfo instance with id: " + id);
try {
AnswerInfo instance = (AnswerInfo) getHibernateTemplate().get(
"com.wj.po.AnswerInfo", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(AnswerInfo instance) {
log.debug("finding AnswerInfo instance by example");
try {
List results = getHibernateTemplate().findByExample(instance);
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding AnswerInfo instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from AnswerInfo as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findByDoctorname(Object doctorname) {
return findByProperty(DOCTORNAME, doctorname);
}
public List findByContent(Object content) {
return findByProperty(CONTENT, content);
}
public List findByAnswerTimes(Object answerTimes) {
return findByProperty(ANSWER_TIMES, answerTimes);
}
public List findAll() {
log.debug("finding all AnswerInfo instances");
try {
String queryString = "from AnswerInfo";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public AnswerInfo merge(AnswerInfo detachedInstance) {
log.debug("merging AnswerInfo instance");
try {
AnswerInfo result = (AnswerInfo) getHibernateTemplate().merge(
detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(AnswerInfo instance) {
log.debug("attaching dirty AnswerInfo instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(AnswerInfo instance) {
log.debug("attaching clean AnswerInfo instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static AnswerInfoDAO getFromApplicationContext(ApplicationContext ctx) {
return (AnswerInfoDAO) ctx.getBean("AnswerInfoDAO");
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
请先学习jdbc
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询