免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 789 | 回复: 0
打印 上一主题 下一主题

我的J2EE学习笔记(1) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-10-23 14:11 |只看该作者 |倒序浏览

刚学习J2EE不久,在struts+oracle+hibernate+myeclipse的环境下自己学了一段,大概3周时间,掌握了一些皮毛,其中一些要点如下:
1、如何用myeclipse提供的根据实现关系-对象的映射
   (1)数据表必须有主键,否则需要修改映射文件
   (2)最好用DAO形式
   (3)用映射文件创建POJO
2、编码问题
    (1)eclipse中的JSP文件乱码,第一行加上
   
    (2)form读入时乱码,见自己的百度BLOG文章
   
http://hi.baidu.com/biguoting/blog/item/a40c8c1080a31201203f2e44.html
3、类型转换
    借鉴资料,创建类型转换的类
     
4、直接使用hibernateDAO操作数据库
        
         try {
      session = HibernateSessionFactory.currentSession();
      tx = session.beginTransaction();
      //Add a new admin
      session.save(studentinfo);
      //session.flush();
      tx.commit ();
     }catch(HibernateException e){
      throw e;
     }finally{
      //if (tx!=null) {
       //tx.rollback();
      //}
      HibernateSessionFactory.closeSession();
     }
5、用hibernate调用存储过程
      
session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
     CallableStatement ps=null;
     Connection conn=null;
     conn=session.connection();
     String   procedure   =   "{call ADD_STUDENTINFO(?,?,?)   }";  
     try{
       ps=conn.prepareCall(procedure);
       ps.setString(1, studentinfo.getSname());
       ps.setDate(2, studentinfo.getBirthday());
       ps.setLong(3, studentinfo.getSex());
       ps.execute();
       tx.commit();
     }
     catch(java.sql.SQLException err)
     {
      System.out.print("error occured in op !");
     }
     finally
     {
      HibernateSessionFactory.closeSession();
     }
还有一些技巧,大部分是自己尝试的,先写这么多吧~~~~


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/4461/showart_189021.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP