zoukankan
html css js c++ java
第一个Hibernate 程序终于测试通过了
java 好多地方都要自己配置,习惯了 vs 的东西,真是不适应。
CurUser.java
package
test;
public
class
CurUser
{
private
String Curid;
private
String Name;
public
String getCurid()
{
return
Curid;
}
public
void
setCurid(String id)
{
this
.Curid
=
id;
}
public
String getName()
{
return
Name;
}
public
void
setName(String name)
{
Name
=
name;
}
}
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
>
测试页面
<%
@ page language
=
"
java
"
import
=
"
java.util.*
"
pageEncoding
=
"
gb2312
"
%>
<%
@ page import
=
"
org.hibernate.*
"
%>
<%
@ page import
=
"
org.hibernate.cfg.*
"
%>
<%
@ page import
=
"
test.CurUser
"
%>
<%
@ page import
=
"
java.sql.*
"
%>
<%
String
path
=
request.getContextPath();
String
basePath
=
request.getScheme()
+
"
://
"
+
request.getServerName()
+
"
:
"
+
request.getServerPort()
+
path
+
"
/
"
;
%>
<!
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
>
<%
try{
//
获得Hibernate配置
SessionFactory sf
=
new
Configuration().configure().buildSessionFactory();
//
开启连接
Session ses
=
sf.openSession();
//
开启事务
Transaction tx
=
ses.beginTransaction();
//
连续写入10条纪录
for
(
int
i
=
0
;i
<
10
;i
++
)
{
CurUser cr
=
new
CurUser();
cr.setName(
"
abc
"
);
ses.save(cr);
}
//
提交事务
tx.commit();
//
关闭连接
ses.close();
out.println(
"
Hibernate 测试成功!
"
);
}
catch(HibernateException e)
{
e.printStackTrace();
out.println(
"
Hibernate 测试异常!
"
);
out.println(e.toString());
}
%>
</
body
>
</
html
>
create
database
if
not
exists
`first`;
USE
`first`;
/**/
/*
数据表 `test` 的表结构
*/
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;
查看全文
相关阅读:
UNIGUI与UNIURLFRAME的互动
unigui结合JS方法记录
如何将uniurlframe中html调用delphi的函数
XE下显示托盘图标(TrayIcon)
Delphi fmx控件在手机滑动与单击的问题
Delphi使用iTools安卓模拟器
Delphi调用SQL分页存储过程实例
分享Pos函数(比FastPos还要快)
Delphi Excel导入 的通用程序转载
Delphi控件cxGrid 如何动态创建列?
原文地址:https://www.cnblogs.com/gwazy/p/965406.html
最新文章
深度学习的激活函数 :sigmoid、tanh、ReLU 、Leaky Relu、RReLU、softsign 、softplus、GELU
机器学习(一)基础常用损失函数、评价指标、距离、指标
DelphiXE10.2.3——跨平台生成验证码图片
unigui+fastReport实现web打印方案
深入-FastReport TfrxReport组件使用
unigui+fastreport报表打印
Delphi Excel导入 的通用程序
ExtJs 入门教程
TeeChart For VCL/FMX V2017使用教程:第一章-准备开始
Delphi XE2 新增 System.Zip 单元, 可用一句话压缩整个文件夹了
热门文章
delphi压缩与解压_不需要特别的控件
UniGui中使用Grid++Report报表控件子报表获取数据的方法
怎么取cxgrid某一列的合计值
delphi 窗体最大化 最小化
Delphi 中的 IfThen 函数
delphi如何在form显示出来后处理指定的事件(例如自动登录)
unidbgrid 设置 单元格颜色
UniGUI的布局使用说明
给uniGUI的表格控件uniDBGrid加上记录序号的列
unigui日志
Copyright © 2011-2022 走看看