您的位置:首页 > 其它

第一个Hibernate 程序终于测试通过了

2007-11-20 11:36 423 查看
java 好多地方都要自己配置,习惯了 vs 的东西,真是不适应。

CurUser.java
package test;

CurUser.hbm.xml

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE hibernate-mapping PUBLIC

"-//Hibernate/Hibernate Mapping DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="test.CurUser" table="test">

<id name="Curid" type="string" unsaved-value="null">

<generator class="uuid.hex"/>

</id>

<property name="Name" type="string"/>

</class>

</hibernate-mapping>

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">

<!-- Generated by MyEclipse Hibernate Tools. -->

<hibernate-configuration>

<session-factory>

<property name="connection.username">root</property>

<property name="connection.url">

jdbc:mysql://localhost/first

</property>

<property name="dialect">

org.hibernate.dialect.MySQLDialect

</property>

<property name="connection.password">root</property>

<property name="connection.driver_class">

com.mysql.jdbc.Driver

</property>

<mapping resource="test/CurUser.hbm.xml" />

</session-factory>

</hibernate-configuration>

测试页面

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->

</head>

<body>

</body>

</html>

create database if not exists `first`;

USE `first`;

DROP TABLE IF EXISTS `test`;

CREATE TABLE `test` (

`Curid` varchar(50) collate utf8_unicode_ci default NULL,

`name` varchar(50) collate utf8_unicode_ci default NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: