Hibernate3.0配置
我的系统Win10(64x),Eclipse jee 2018-09 ,Sql2018版本。
以下是Hibernate3.0配置包
链接:https://pan.baidu.com/s/10KizbyeMwjnHlG4JQ8WtaA
提取码:iptb
以下再lib下导入8个包。
以下是hibernate.cfg.xml(创建文件)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" >
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="connection.url">jdbc:sqlserver://localhost:1433; DatabaseName=Student</property>
<property name="connection.username">sa</property>
<property name="connection.password">******</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hbm2ddl.auto">update</property>
<property name="show_sql">true</property>
<mapping resource="domain/hf.hbm.xml" /><!--加入一个空格-->
</session-factory>
</hibernate-configuration>
以下是一个用例建立hf表
hf.hbm.xml文件(跟domain再同一个package下)
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="domain">
<class name="hf">
<id name="id" type="java.lang.Integer">
<column name="id"/>
<generator class="native"/>
</id>
<property name="name"/>
<property name="birthday"/>
</class>
</hibernate-mapping>
bean代码
package domain;
import java.util.Date;
public class hf {
private Integer id;
private String name;
private String birthday;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
}
loginservlet类
package src.servlet; import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import domain.hf;
/**
* Servlet implementation class loginservlet
*/
public class loginservlet extends HttpServlet {
private static final long serialVersionUID = 1L; /**
* @see HttpServlet#HttpServlet()
*/
public loginservlet() {
super();
// TODO Auto-generated constructor stub
} /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setHeader("content-type","text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
String name=request.getParameter("name");
String birthday=request.getParameter("birthday");
Configuration cfg =new Configuration();
cfg.configure();
SessionFactory sf=cfg.buildSessionFactory();
Session se=null;
Transaction tx=null;
try {
se=sf.openSession();
tx=se.beginTransaction();
hf user=new hf();
user.setName(name);
user.setBirthday(birthday);
se.save(user);
tx.commit();
}catch(Exception e) {
if(tx != null) tx.rollback();
}finally {
if(se != null) se.close();
PrintWriter out=response.getWriter();
out.println("注册操作完成!");//乱码?
System.out.println(name);
System.out.println(birthday);
}
} /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
} }
Web.xml配置
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<servlet>
<servlet-name>loginservlet</servlet-name>
<servlet-class>src.servlet.loginservlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>loginservlet</servlet-name>
<url-pattern>/loginservlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
login JSP页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户注册提交页面</title>
</head>
<body>
<form action="loginservlet" method="post">
用户名:<input type="text" name="name"><br><br>
出生日期:<input type="text" name="birthday"><br><br>
<input type="submit" value="登录">
</form>
</body>
</html>
数据运行成功的结果:

Hibernate3.0配置的更多相关文章
- hibernate3.0 org.dom4j.DocumentException: Connection timed out: connect Nested exception:
hibernate3.0 org.dom4j.DocumentException: Connection timed out: connect Nested exception: 所报异常: 严重 ...
- IIS运行.NET4.0配置
IIS运行.NET4.0配置 “/CRM”应用程序中的服务器错误.配置错误说明: 在处理向该请求提供服务所需的配置文件时出错.请检查下面的特定错误详细信息并适当地修改配置文件. 分析器错误消息: 无法 ...
- kafka0.9.0及0.10.0配置属性
问题导读1.borker包含哪些属性?2.Producer包含哪些属性?3.Consumer如何配置?borker(0.9.0及0.10.0)配置Kafka日志本身是由多个日志段组成(log segm ...
- VC++6.0 配置CppUTest测试环境
最近看<软件项目成功之道>,书中无数次提及到“单元测试”对于项目成败的重要性,看到同事将CppUTest用于Linux动态库测试,于是在VC++6.0环境下搭建一个基于CppUTest的单 ...
- win7下VS2015+opencv3.1.0配置
由于opencv与vs的适配版本不同,本人在官网下载opencv3.1.0,其可以和VS2013.VS2015适配,文中以VS2015为例 opencv2.4.13-----vc11;vc12 ope ...
- Windows 8.0上Eclipse 4.4.0 配置CentOS 6.5 上的Hadoop2.2.0开发环境
原文地址:http://www.linuxidc.com/Linux/2014-11/109200.htm 图文详解Windows 8.0上Eclipse 4.4.0 配置CentOS 6.5 上的H ...
- windows下Qt5.1.0配置android环境搭建 good
1.首先下载好需要配置的软件: 1>Qt 5.1.0 for Android (Windows 32-bit, 716 MB)(Info)下载地址: http://qt-project.org/ ...
- ganglia监控hadoop2.0配置方法
ganglia监控hadoop2.0配置方法前提:hadoop2.0集群已安装ganglia监控工具第一步:Hadoop用户登录集群每一个节点,修改文件:vi /opt/hadoop-2.0.0-cd ...
- nginx1.9.4 +php 5.5.29+yii2.0配置手册
nginx1.9.4 +php 5.5.29+yii2.0配置手册 目录 一. php5.5.29安装配置 2 二. nginx1.9.4安装配置 2 三. yii2.0 ...
随机推荐
- android 开发 View _6_Canvas详解
牛逼大神的博客地址:http://www.gcssloop.com/customview/Canvas_BasicGraphics 安卓自定义View进阶-Canvas之绘制图形 在上一篇自定义Vie ...
- Mac平台下部署UE4工程到iOS设备的流程
1.开发环境 UE4.Xcode.iOS版本情况如下: 1.UE4:当前最新版本Unreal Engine 4.17.2. 2.Xcode:当前最新版本Xcode9.0. 3.iOS:当前最新版本iO ...
- typedef typename
所以根据上述两条分析, typedef typename RefBase::weakref_type weakref_type; 语句的真是面目是: typedef创建了存在类型的别名,而typen ...
- MQTT协议
MQTT(Message Queue Telemerty Transport)是一种二进制协议,主要用于服务器和那些低功耗的物联网设备(IoT)之间的通信. 它位于 TCP 协议的上层,除了提供发布- ...
- 恢复mysql 中root 用户的所有权限
今天在研究数据库的时候不小心吧root用户的权限全给关了.这就尴尬了. 找了半天的解决方案. 如果你的用grant all 无法设定某个用户的权限可以试试这个方法. 1停止mysql服务器.使用ski ...
- C++ 11 创建和使用 unique_ptr
unique_ptr 不共享它的指针.它无法复制到其他 unique_ptr,无法通过值传递到函数,也无法用于需要副本的任何标准模板库 (STL) 算法.只能移动unique_ptr.这意味着,内存资 ...
- scrapy爬虫框架处理流程简介
1.SPIDERS的yeild将request发送给ENGIN2.ENGINE对request不做任何处理发送给SCHEDULER3.SCHEDULER( url调度器),生成request交给ENG ...
- 绑定checkedComboBox
using System; namespace CommonLib{ /// <summary> /// CommonCode 的摘要说明. /// </summary> [S ...
- shell一出手
1.查看有多少个IP访问: awk '{print $1}' log_file|sort|uniq|wc -l 2.查看某一个页面被访问的次数: grep "/index.php" ...
- 丑数(python)
题目描述 把只包含质因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因为它包含质因子7. 习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第N个丑数. # ...