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;
}
}
/p>
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
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 threadLocal = new ThreadLocal();
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);
}
}
/p>
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
org.hibernate.dialect.OracleDialect
jdbc:oracle:thin:@localhost:1521:xe
abing
abing
oracle.jdbc.driver.OracleDriver
OracleConnection