Oracle入门案例:

1.创建实体类Student 并重写ToString方法

package cn.happy.entity;

public class Student {

    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 Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
@Override
public String toString() {
return "Student [name=" + name + ", age=" + age + ", id=" + id + "]";
}
private String name;
private Integer age;
private Integer id; }

2.导入jar包

3.创建大配置关联小配置

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
<property name="connection.username">scott</property>
<property name="connection.password">0123</property>

<!-- 输出所有 SQL 语句到控制台。 -->
<property name="hibernate.show_sql">true</property>

<!-- 在 log 和 console 中打印出更漂亮的 SQL。 -->
<property name="hibernate.format_sql">true</property>
<!-- 方言 -->
<property name="hibernate.dialect"> org.hibernate.dialect.Oracle10gDialect</property>

<property name="hbm2ddl.auto">update</property>

<mapping resource="cn/happy/entity/Student.hbm.xml"/>

</session-factory>

</hibernate-configuration>

4.编写小配置coding='utf-8'?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="cn.happy.entity">
<class name="Student" table="Student">
<id name="id" type="int" column="id">
</id>
<property name="name" type="string" column="name"/>
<property name="age" type="int" column="age"/>
</class>
</hibernate-mapping>

5.工具类

package cn.happy.entity;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration; public class HibernateUtil {
private static Configuration cfg=new Configuration().configure();
private static SessionFactory factory=cfg.buildSessionFactory(); //01.方法返回session
public static Session getSession(){
return factory.openSession();
} //02.关闭session
public static void closeSession(){
getSession().close();
} }

6.测试类

    //  1.2 修改学生 

    @Test
public void updateTest(){
Session session = HibernateUtil.getSession(); //不被上下文跟踪对象
/*Student stu=new Student();
stu.setId(3);
stu.setName("微冷的雨训练营");*/ //方式二:如何用呗上下文跟踪的方式
//检索出一条记录,一个实体对象
Student stu= (Student)session.load(Student.class,3);
stu.setName("金龙加油!!!!"); Transaction tx = session.beginTransaction();
session.update(stu);
tx.commit();
HibernateUtil.closeSession();
System.out.println("update ok!");
}

Oracle 增删改查的更多相关文章

  1. Java 数据库操作oracle增删改查,通用封装基于hashmap

    pt1:首先安装oracle连接驱动 下载地址:https://pan.baidu.com/s/1jW_ofgU4eJmAn7Y2J5B46A  密码:epkz 1.将ojdbc6.jar导入项目中 ...

  2. oracle增删改查

    =======================批量删除,只留前十条数据. delete from THIRD_PARTY_MERCHANT a where a.rowid in ( select ro ...

  3. Oracle增删改查sql语句

    --创建表空间 create tablespace waterboss datafile 'd:\waterboss.dbf' size 100m autoextend on next 10m --创 ...

  4. oracle增删改查基本语法(DDL/DML)整理

    DDL:Data Definition Language(数据库定义语言)DML:Data Manipulation Language(数据库操作语言) 一.表结构操作(create table.al ...

  5. ORACLE增删改查以及case when的基本用法

    1.创建table create table test01( id int not null primary key, name ) not null, gender ) not null, age ...

  6. sql server连接oracle并实现增删改查

    需要一个软件ODAC112040Xcopy_64bit 我连接的oracle是11g r2  sqlserver 是 2016 软件下载 https://pan.baidu.com/s/1OpYmpR ...

  7. 对oracle里面clob字段里面xml的增删改查学习

    这段时间,我使用系统表里面有clob字段里面存放的xml信息,我们如何对xml进行增删改查操作呢,自己参考了很多也学到很多,给大家分享一下 首先我们先建测试表 CREATE TABLE EFGP_23 ...

  8. Oracle学习总结_day01_day02_表的创建_增删改查_约束

    本文为博主辛苦总结,希望自己以后返回来看的时候理解更深刻,也希望可以起到帮助初学者的作用. 转载请注明 出自 : luogg的博客园 谢谢配合! 更新: SELECT * FROM (SELECT R ...

  9. web项目总结——通过jsp+servlet实现对oracle的增删改查功能

    1.DAO模式 分包:依次建立 entity:实体包,放的是跟oracle数据库中表结构相对应的对象的属性,也就是这个对象有什么 dao:增删改查接口,实现增删改查的具体方法 service:同dao ...

随机推荐

  1. html页面内容超出后显示水平滚动条的问题

    这个问题已经遇到好几次,解决起来也熟练了很多.   出现这种问题一般都是html或页面中的某一内部元素宽度超了. 下面总结我遇到的几种情况: 1.某一内部元素width设为100%,然而它还有bord ...

  2. MySQL中CURRENT_TIMESTAMP(转)

    1. MySQL 获得当前时间戳函数:current_timestamp, current_timestamp()  代码如下   mysql> select current_timestamp ...

  3. Thinkcmf 二次开发

    一.   创建模板 demo 1 Tpl下创建demo文件-----后台启用新的模板 (网站信息--模板方案) 2 在模板在tpl/demo目录下创建Portal目录,然后在Portal目录下创建in ...

  4. 使用CSS3制作立体效果的导航菜单

    效果如下: 也可以点击网址查看效果:http://keleyi.com/keleyi/phtml/html5/12.htm 请使用支持CSS3的浏览器访问本页面,获得更好效果. 源代码: <st ...

  5. input checkbox 扩大点击范围

    <div style="width:100%;height:100px;"><input type="checkbox" onclick=&q ...

  6. compileDebugJavaWithJavac

    学习笔记 compileDebugJavaWithJavac,缺少插件,在module app gradle文件最上面添加一段 apply plugin: 'me.tatarka.retrolambd ...

  7. IOS开发基础知识--碎片48

    1:Assertion failure in dequeueReusableCellWithIdentifier:forIndexPath:  static NSString *CellIdentif ...

  8. iOS程序破解——class-dump获取头文件

    原文在此:http://www.cnblogs.com/mddblog/p/4942894.html 一.简述 class-dump顾名思义,是用来dump目标对象class信息的工具.它根据oc的r ...

  9. Android添加图片到ListView或者 RecyclerView显示

    先上图 点击+号就去选择图片 实际上这个添加本身就是一个ListView或者 RecyclerView 只是布局有些特殊 item <?xml version="1.0" e ...

  10. popupwindow展示

    样式: layout: popup_appinfo.xml <?xml version="1.0" encoding="utf-8"?> <L ...