我的系统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配置的更多相关文章

  1. hibernate3.0 org.dom4j.DocumentException: Connection timed out: connect Nested exception:

    hibernate3.0 org.dom4j.DocumentException: Connection timed out: connect Nested exception:   所报异常: 严重 ...

  2. IIS运行.NET4.0配置

    IIS运行.NET4.0配置 “/CRM”应用程序中的服务器错误.配置错误说明: 在处理向该请求提供服务所需的配置文件时出错.请检查下面的特定错误详细信息并适当地修改配置文件. 分析器错误消息: 无法 ...

  3. kafka0.9.0及0.10.0配置属性

    问题导读1.borker包含哪些属性?2.Producer包含哪些属性?3.Consumer如何配置?borker(0.9.0及0.10.0)配置Kafka日志本身是由多个日志段组成(log segm ...

  4. VC++6.0 配置CppUTest测试环境

    最近看<软件项目成功之道>,书中无数次提及到“单元测试”对于项目成败的重要性,看到同事将CppUTest用于Linux动态库测试,于是在VC++6.0环境下搭建一个基于CppUTest的单 ...

  5. win7下VS2015+opencv3.1.0配置

    由于opencv与vs的适配版本不同,本人在官网下载opencv3.1.0,其可以和VS2013.VS2015适配,文中以VS2015为例 opencv2.4.13-----vc11;vc12 ope ...

  6. 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 ...

  7. windows下Qt5.1.0配置android环境搭建 good

    1.首先下载好需要配置的软件: 1>Qt 5.1.0 for Android (Windows 32-bit, 716 MB)(Info)下载地址: http://qt-project.org/ ...

  8. ganglia监控hadoop2.0配置方法

    ganglia监控hadoop2.0配置方法前提:hadoop2.0集群已安装ganglia监控工具第一步:Hadoop用户登录集群每一个节点,修改文件:vi /opt/hadoop-2.0.0-cd ...

  9. 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 ...

随机推荐

  1. background url base64

    各自含义:data: ----获取数据类型名称image/gif; -----指数据类型名称base64 -----指编码模式AAAAA ------指编码以后的结果. background-imag ...

  2. 深入理解Java虚拟机之Java内存区域随笔

    1.java内存区域与内存溢出异常 Java 虚拟机在执行 Java 程序的过程中会把它管理的内存划分成若干个不同的数据区域:1.程序计数器,2.栈(虚拟机栈和本地方法栈 ),3.堆,4.方法区(包含 ...

  3. 并发中的volatile

    目录 1. 概述 2. volatile的特性 3. volatile写-读的内存语义 4. volatile内存语义的实现 5. JSR-133为什么要增强volatile的内存语义 6. 总结 1 ...

  4. MySQL中IN子查询会导致无法使用索引

    今天看到一个博客园的一篇关于MySQL的IN子查询优化的案例,一开始感觉有点半信半疑(如果是换做在SQL Server中,这种情况是绝对不可能的,后面会做一个简单的测试.)随后动手按照他说的做了一个表 ...

  5. vue 初始化data中的数据

    Object.assign(this.$data, this.$options.data());

  6. mysql_day03

    MySQL-Day02回顾1.表记录的管理 1.删除表记录 1.delete from 表名 where 条件; ## 不加where条件全部删除 2.更新表记录 1.update 表名 set 字段 ...

  7. 工艺CODE

  8. Linux 里的 2>&1含义

    我们在Linux下经常会碰到nohup command>/dev/null 2>&1 &这样形式的命令.首先我们把这条命令大概分解下: 首先就是一个nohup:表示当前用户 ...

  9. jar与war包区别,转自https://www.jianshu.com/p/3b5c45e8e5bd

    https://www.jianshu.com/p/3b5c45e8e5bd

  10. python 06函数

    python中函数定义方法: def test(x): "The function definitions" x+=1 return x def:定义函数的关键字test:函数名( ...