更改数据库连接的URL
在最后加上;SelectMethod=cursor例:
jdbc:microsoft:sqlserver://localhost:1433;user=username;password=pass;SelectMethod=cursor;
在最后加上;SelectMethod=cursor例:
jdbc:microsoft:sqlserver://localhost:1433;user=username;password=pass;SelectMethod=cursor;
解决方案 »
- 求助: JSF(primefaces)+hibernate+Spring java.io.NotSerializableException
- 有懂专家系统和CLIPS的吗
- Web Services 教程 推荐
- 一个常见的 关于 ORM 界面绑定的问题 目前为止,一直还没人解答出来
- 哪位仁兄又weblogic的中文教程
- 急,斑斑手下留情:CNN正对二战倭人是否应对慰安妇道歉问题投票,No竟远多于Yes
- 如何实现自动更新?
- jboss无法启动
- 看似简单的问题,可把我难住
- HttpURLConnection不能设置Authorization
- 请大家推荐一个不错的xml plugin
- java登录文件系统错误
package hibernateone;import net.sf.hibernate.cfg.*;
import net.sf.hibernate.*;
import java.util.*;
import java.io.*;public abstract class HibernateBase {
protected SessionFactory sessionFactory; //会话工厂,用于创建会话
protected Session session; //hibernate会话
protected Transaction transaction; //hiberante事务
public HibernateBase()throws HibernateException
{
this.initHibernate();
}
// 帮助方法
protected void initHibernate()
throws HibernateException { // 装载配置,构造SessionFactory对象
sessionFactory = new Configuration().configure().buildSessionFactory();
}
/**
*开始一个hibernate事务
*/
protected void beginTransaction()
throws HibernateException { session = sessionFactory.openSession();
transaction = session.beginTransaction();
}
/**
*结束一个hibernate事务。
*/
protected void endTransaction(boolean commit)
throws HibernateException { if (commit) {
transaction.commit();
} else {
//如果是只读的操作,不需要commit这个事务。
transaction.rollback();
}
session.close();
} }
import net.sf.hibernate.cfg.*;
import java.util.*;
public class CourseBean extends HibernateBase { public CourseBean() throws HibernateException {
super();
}
/**
*增加一个Course
*/
public void addCourse(Course st)throws HibernateException
{
beginTransaction();
session.save(st);
endTransaction(true);
} /**
*查询系统中所有的Course,返回的是包含有Course持久对象的Iterator。
*/
public Iterator getAllCourses()throws HibernateException
{
String queryString = "select courses from Course as courses";
beginTransaction();
Query query = session.createQuery(queryString);
Iterator it= query.iterate();
return it;
}
/**
*删除给定ID的course
*/
public void deleteCourse(String id)throws HibernateException
{
beginTransaction();
Course course=(Course)session.load(Course.class,id);
session.delete(course);
endTransaction(true);
} /**
*按course的名字进行模糊查找,返回的是包含有Course持久对象的Iterator。
*/
public Iterator getSomeCourse(String name)throws HibernateException
{
String queryString = "select c from Course as c where c.name like :name" ;
beginTransaction();
Query query = session.createQuery(queryString);
query.setString("name", "%"+name+"%");
Iterator it= query.iterate();
return it;
}
}
<%@ page import="java.sql.*,java.util.*,hibernateone.Course" %>
<jsp:useBean id="courseBusiness" class="hibernateone.CourseBean" scope="page"/>
…
<% try
{
Iterator it=courseBusiness.getAllCourses();
while(it.hasNext())
{
Course temp=(Course)it.next();
out.println("<tr><td>"+temp.getId()+"</td>");
out.println("<td>"+temp.getName()+"</td></tr>");
}
}
catch(Exception e)
{
out.println(e.getMessage());
}
%>大家在帮我看看呀。 谢谢了哈
最后请问一下。那儿能下MiddleGen-Hibernate 呀。 我找到的网址不知道 为什么都 不能下。
郁闷
兄弟 们。那儿能下MiddleGen-Hibernate 呀。 我找到的网址不知道 为什么都 不能下。