少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

          package com.abin.lee.bean;

          /**
           * Userbean entity. @author MyEclipse Persistence Tools
           */

          public class UserBean implements java.io.Serializable {

           // Fields

           private String id;
           private String username;
           private String password;

           // Constructors

           /** default constructor */
           public UserBean() {
           }

           /** minimal constructor */
           public UserBean(String id) {
            this.id = id;
           }

           /** full constructor */
           public UserBean(String id, String username, String password) {
            this.id = id;
            this.username = username;
            this.password = password;
           }

           // Property accessors

           public String getId() {
            return this.id;
           }

           public void setId(String id) {
            this.id = id;
           }

           public String getUsername() {
            return this.username;
           }

           public void setUsername(String username) {
            this.username = username;
           }

           public String getPassword() {
            return this.password;
           }

           public void setPassword(String password) {
            this.password = password;
           }

          }





          <?xml version="1.0" encoding="utf-8"?>
          <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "<!--
              Mapping file autogenerated by MyEclipse Persistence Tools
          -->
          <hibernate-mapping>
              <class name="com.abin.lee.bean.UserBean" table="USERBEAN" schema="ABING">
                  <id name="id" type="string">
                      <column name="ID" length="80" />
                      <generator class="assigned" />
                  </id>
                  <property name="username" type="string">
                      <column name="USERNAME" length="80" />
                  </property>
                  <property name="password" type="string">
                      <column name="PASSWORD" length="80" />
                  </property>
              </class>
          </hibernate-mapping>






          package com.abin.lee.dao;

          import java.sql.SQLException;

          import org.hibernate.SQLQuery;
          import org.hibernate.Session;
          import org.hibernate.SessionFactory;
          import org.hibernate.Transaction;
          import org.hibernate.cfg.Configuration;

          public class UserDao {
           private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
           private static SessionFactory sessionFactory;
           static {
            sessionFactory=new Configuration().configure().buildSessionFactory();
           }
           public static Session GetSession(){
            Session session=(Session)threadLocal.get();
            if(null == session|| !session.isOpen()){
             if(null==sessionFactory){
              sessionFactory=new Configuration().configure().buildSessionFactory();
             }
             session=(sessionFactory!=null)?sessionFactory.openSession():null;
             threadLocal.set(session);
            }
            return session;
           }
           
           public static int insert(String id,String usr,String pwd) throws SQLException{
            UserDao UserDao=new UserDao();
            Session session=UserDao.GetSession();
            Transaction tx=session.beginTransaction();
            SQLQuery sqlQuery = session.createSQLQuery("{call insertObj(?,?,?)}");
            sqlQuery.setParameter(0, id);
            sqlQuery.setParameter(1, usr);
            sqlQuery.setParameter(2, pwd);
            int result=sqlQuery.executeUpdate();
            System.out.println("result="+result);
            return result;
           }
           
          }






          package com.abin.lee.test;

          import java.sql.SQLException;

          import junit.framework.TestCase;

          import com.abin.lee.dao.UserDao;

          public class UserTest extends TestCase{
           public void test() throws SQLException{
            UserDao user=new UserDao();
            int success=user.insert("abin","abing","bing");
            System.out.println("success="+success);
           }
          }








          <?xml version='1.0' encoding='UTF-8'?>
          <!DOCTYPE hibernate-configuration PUBLIC
                    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                    "

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

           <session-factory>
            <property name="dialect">
             org.hibernate.dialect.OracleDialect
            </property>
            <property name="connection.url">
             jdbc:oracle:thin:@localhost:1521:xe
            </property>
            <property name="connection.username">abing</property>
            <property name="connection.password">abing</property>
            <property name="connection.driver_class">
             oracle.jdbc.driver.OracleDriver
            </property>
            <property name="myeclipse.connection.profile">
             OracleConnection
            </property>
            <mapping resource="com/abin/lee/bean/UserBean.hbm.xml" />
             
              </session-factory>

          </hibernate-configuration>








          主站蜘蛛池模板: 楚雄市| 苍溪县| 托里县| 台东县| 格尔木市| 张掖市| 邵阳市| 团风县| 双流县| 广水市| 南宁市| 浏阳市| 吉首市| 林州市| 荔浦县| 扬中市| 通城县| 巴彦县| 临夏市| 文昌市| 海宁市| 兴和县| 日喀则市| 潮安县| 芜湖市| 古交市| 晴隆县| 西乌珠穆沁旗| 平顺县| 九龙县| 青龙| 福州市| 理塘县| 肇东市| 青海省| 深水埗区| 车险| 固安县| 彩票| 沙田区| 松桃|