📄 userinfodao.java
字号:
package com.shop.model.dao.userinfo;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.shop.model.utils.DataBaseConn;
import com.shop.vo.userinfo.UserInfoVO;
public class UserInfoDAO {
public List<UserInfoVO> findAllUserInfoVO() {
Connection conn = null;
Statement st = null;
ResultSet rst = null;
String select = "select * from UserInfo";
List<UserInfoVO> userList = new ArrayList<UserInfoVO>();
DataBaseConn dbconn = new DataBaseConn();
conn = dbconn.getConnection();
try {
st = conn.createStatement();
rst = st.executeQuery(select);
while (rst.next()) {
UserInfoVO user = new UserInfoVO();
user.setUserID(rst.getString("userid"));
user.setUsername(rst.getString("username"));
user.setSex(rst.getString("sex"));
user.setAge(rst.getInt("age"));
user.setPostalCode(rst.getString("postalCode"));
user.setSchoolage(rst.getString("schoolage"));
user.setRegisterDate(rst.getDate("registerDate"));
userList.add(user);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (rst != null) {
try {
rst.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (st != null) {
try {
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return userList;
}
public List<UserInfoVO> searchUserInfo(String sql) {
Connection conn = null;
Statement st = null;
ResultSet rst = null;
String select = "select * from UserInfo where " + sql;
List<UserInfoVO> userList = new ArrayList<UserInfoVO>();
DataBaseConn dbconn = new DataBaseConn();
conn = dbconn.getConnection();
try {
st = conn.createStatement();
rst = st.executeQuery(select);
while (rst.next()) {
UserInfoVO user = new UserInfoVO();
user.setUserID(rst.getString("userid"));
user.setUsername(rst.getString("username"));
user.setSex(rst.getString("sex"));
user.setUserPassword(rst.getString("userpassword"));
user.setAge(rst.getInt("age"));
user.setPersonLike(rst.getString("personlike"));
user.setAddress(rst.getString("address"));
user.setPostalCode(rst.getString("postalCode"));
user.setSchoolage(rst.getString("schoolage"));
user.setRegisterDate(rst.getDate("registerDate"));
user.setUserType(rst.getString("usertype"));
userList.add(user);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (rst != null) {
try {
rst.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (st != null) {
try {
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return userList;
}
public UserInfoVO getUserInfoById(String id) {
Connection conn = null;
Statement st = null;
ResultSet rst = null;
String select = "select * from UserInfo where userid =" + id;
DataBaseConn dbconn = new DataBaseConn();
UserInfoVO user = null;
conn = dbconn.getConnection();
try {
st = conn.createStatement();
rst = st.executeQuery(select);
while (rst.next()) {
user = new UserInfoVO();
user.setUserID(rst.getString("userid"));
user.setUsername(rst.getString("username"));
user.setSex(rst.getString("sex"));
user.setUserPassword(rst.getString("userpassword"));
user.setAge(rst.getInt("age"));
user.setPersonLike(rst.getString("personlike"));
user.setAddress(rst.getString("address"));
user.setPostalCode(rst.getString("postalCode"));
user.setSchoolage(rst.getString("schoolage"));
user.setRegisterDate(rst.getDate("registerDate"));
user.setUserType(rst.getString("usertype"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (rst != null) {
try {
rst.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (st != null) {
try {
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return user;
}
public void deleteUserInfo(String[] ids) {
StringBuffer delete = new StringBuffer(
"delete from UserInfo where userid in (0");
if (ids != null && ids.length > 0) {
for (String id : ids) {
delete.append(",").append(id);
}
delete.append(")");
DataBaseConn dbconn = new DataBaseConn();
Connection conn = null;
Statement st = null;
try {
conn = dbconn.getConnection();
st = conn.createStatement();
st.execute(delete.toString());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (st != null) {
st.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public void updateUserInfo(String uuid, String usertype){
StringBuffer update =new StringBuffer("update UserInfo set ");
update.append("usertype = '").append(usertype).append("' where userid=").append(uuid);
DataBaseConn dbconn = new DataBaseConn();
Connection conn = null;
Statement st = null;
try {
conn = dbconn.getConnection();
st = conn.createStatement();
st.execute(update.toString());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (st != null) {
st.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -