📄 springhibernatedaoimpl.java
字号:
/*
* Created on Aug 5, 2005
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package com.free.dao;
import java.util.ArrayList;
import java.util.Collection;
import java.util.*;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.hibernate.criterion.*;
import com.free.dao.hibernate.*;
import com.free.web.common.UsersList;
// Java Imports
import java.sql.*;
/**
* <p>Title: Eclipse Plugin Development</p>
* <p>Description: Free download</p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: Free</p>
* @author gan.shu.man
* @version 1.0
*/
public class SpringHibernateDAOImpl extends HibernateDaoSupport implements
ISpringHibernateDAO {
public boolean checkUserLogin(String strUserName, String strPassword)
throws DataAccessException, java.sql.SQLException {
boolean valid = false;
Connection conn = this.getSession().connection();
Statement smt = conn.createStatement();
ResultSet rs;
//判断用户名和密码在login表是是否存,从而验证用户的有较性
String query = "select id from login where loginid='" + strUserName
+ "' and password='" + strPassword + "'";
rs = smt.executeQuery(query);
if (rs.next() == true) {
valid = true;
} else {
valid = false;
}
smt.close();
rs.close();
conn.close();
return valid;
}
public void addUser(com.free.dao.hibernate.User obj)
throws DataAccessException {
//添加用户
getHibernateTemplate().save(obj);
}
public void updateUser(com.free.dao.hibernate.User obj)
throws DataAccessException {
//更新用户
getHibernateTemplate().update(obj);
}
public com.free.dao.hibernate.User loadUser(String id)
throws DataAccessException {
//加载用户信息
return (com.free.dao.hibernate.User) getHibernateTemplate().get(
User.class, new Integer(id));
}
public boolean checkValidUserName(String strUserid)
throws DataAccessException, java.sql.SQLException {
boolean valid = false;
Connection conn = this.getSession().connection();
Statement smt = conn.createStatement();
ResultSet rs;
//检查用户登录名是否存在,判断是否能添加此用户
String query = "select id from login where loginid='" + strUserid + "'";
rs = smt.executeQuery(query);
if (rs.next() == true) {
valid = true;
} else {
valid = false;
}
smt.close();
rs.close();
conn.close();
return valid;
}
public int getUserId(String strUserid) throws DataAccessException,
java.sql.SQLException {
Connection conn = this.getSession().connection();
Statement smt = conn.createStatement();
ResultSet rs;
//根据登录名,找到对应的持久化对象的ID号
String query = "select id from login where loginid='" + strUserid + "'";
rs = smt.executeQuery(query);
rs.next();
int id = rs.getInt("id");
smt.close();
rs.close();
conn.close();
return id;
}
public String[] retriveUserForgetPassword(String strUserName,
String strEmail) throws DataAccessException, java.sql.SQLException {
Connection conn = this.getSession().connection();
Statement smt = conn.createStatement();
ResultSet rs;
String query;
if (strUserName != "") {
query = "select password,email,loginid from login where loginid='"
+ strUserName + "'";
} else {
query = "select password,email,loginid from login where email='"
+ strEmail + "'";
}
rs = smt.executeQuery(query);
String[] returnValues = new String[3];
while (rs.next()) {
//查找对应用户信息
returnValues[0] = rs.getString("password");
returnValues[1] = rs.getString("email");
returnValues[2] = rs.getString("loginid");
}
smt.close();
rs.close();
conn.close();
if (returnValues[0] != null) {
return returnValues;
} else {
String[] errorValues = new String[2];
errorValues[0] = "error";
return errorValues;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -