⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mysqlordinarydaoimpl.java

📁 电子商务网站前台代码。基于开源软件编写
💻 JAVA
字号:
package dao;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class MySqlOrdinaryDAOImpl extends CommonUserDAOImpl implements OrdinaryDAO {

	private Connection conn;	

	//插入成功输出true,否则因为异常返回false
	public boolean insertOrdinaryUser(OrdinaryUserTO userTO) {
		// TODO Auto-generated method stub
		conn = this.getConnect();
		try {
			PreparedStatement preproc = conn.prepareStatement("insert usertable(userName,userPassword,role,realName,sex,e_Mail,address,phoneNum,userDescribe) values(?,?,?,?,?,?,?,?,?)");
			preproc.setString(1,userTO.getName());
			preproc.setString(2,userTO.getPassword());
			preproc.setString(3,userTO.getRole());
			preproc.setString(4,userTO.getRealName());
			preproc.setString(5,userTO.getSex());
			preproc.setString(6,userTO.getEmail());
			preproc.setString(7,userTO.getAddress());
			preproc.setString(8,userTO.getPhone());
			preproc.setString(9,userTO.getDescribe());
			preproc.execute();			
			return true;
		}catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	public boolean updateOrdinaryUser(OrdinaryUserTO userTO) {
		// TODO Auto-generated method stub
		conn = this.getConnect();
		try {			
			PreparedStatement preproc = conn.prepareStatement("update usertable set userPassword=?,role=?,sex=?,e_Mail=?,telNum=?,address=? where userName=?");
			preproc.setString(1,userTO.getPassword());
			preproc.setString(2,userTO.getRole());
			preproc.setString(3,userTO.getSex());
			preproc.setString(4,userTO.getEmail());
			preproc.setString(5,userTO.getPhone());
			preproc.setString(6,userTO.getAddress());
			preproc.setString(7,userTO.getName());
			preproc.execute();
			return true;
		}catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}		
	}	

	public OrdinaryUserTO selectOrdinaryUser(String username) {
		// TODO Auto-generated method stub
		conn = this.getConnect();
		try {			
			PreparedStatement preproc = conn.prepareStatement("select userName,userPassword,role,realName,sex,e_Mail,address,phoneNum,userDescribe from usertable where userName=?");
			preproc.setString(1,username);		
			preproc.execute();
			ResultSet rs = preproc.getResultSet();
			
			if(rs.next()){
				OrdinaryUserTO userTo = new OrdinaryUserTO();
				userTo.setName(rs.getString("userName"));
				userTo.setPassword(rs.getString("userPassword"));
				userTo.setRole(rs.getString("role"));
				userTo.setRealName(rs.getString("realName"));
				userTo.setSex(rs.getString("sex"));
				userTo.setEmail(rs.getString("e_Mail"));
				userTo.setAddress(rs.getString("address"));
				userTo.setPhone(rs.getString("phoneNum"));
				userTo.setDescribe(rs.getString("userDescribe"));
				return userTo;
			}else
				return null;
			
		}catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}				
	}

	public boolean deleteOrdinaryUser(String username) {
		// TODO Auto-generated method stub
		conn = this.getConnect();
		try {
			CallableStatement callproc = conn.prepareCall("{call deleteUser(?)}");			
			callproc.setString("username",username);			
			callproc.execute();
			return true;
		}catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}	
	}	

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -