TypeDao.java
上传用户:xinkaifrp
上传日期:2021-05-08
资源大小:372k
文件大小:2k
- package com.financing.dao;
- import com.financing.entity.Type;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class TypeDao extends DBBase{
-
-
- public List<Type> getAllType(Integer userId){
- stmt=DBConnection.createStmt();
- List<Type> type=new ArrayList<Type>();
- try {
- rs = stmt.executeQuery("select id,type_name from f_type where user_id="+userId+"");
- while(rs.next()){
- Type t=new Type( rs.getInt("id"),rs.getString("type_name"));
- type.add(t);
- }
- } catch (SQLException ex) {
- Logger.getLogger(TypeDao.class.getName()).log(Level.SEVERE, null, ex);
- }
- return type;
- }
- public boolean addType(String typeName,Integer userId){
- stmt=DBConnection.createStmt();
- boolean result=false;
- try {
- stmt.executeUpdate("insert into f_type(type_name,user_id) values('" + typeName + "'," + userId + ")");
- result=true;
- } catch (SQLException ex) {
- Logger.getLogger(TypeDao.class.getName()).log(Level.SEVERE, null, ex);
- }
- return result;
- }
- public boolean udpateType(String oldName,String newName,Integer userId){
- String sql="update f_type set type_name='"+newName+"' where user_id="+userId+" and type_name='"+oldName+"'";
- boolean result=false;
- stmt=DBConnection.createStmt();
- try {
- stmt.executeUpdate(sql);
- result=true;
- } catch (SQLException ex) {
- Logger.getLogger(TypeDao.class.getName()).log(Level.SEVERE, null, ex);
- }
- return result;
- }
- public boolean deleteType(String typeName,Integer userId){
- String sql="delete from f_type where type_name='"+typeName+"' and user_id="+userId;
- boolean result=false;
- stmt=DBConnection.createStmt();
- try {
- stmt.executeUpdate(sql);
- result=true;
- } catch (SQLException ex) {
- Logger.getLogger(TypeDao.class.getName()).log(Level.SEVERE, null, ex);
- }
- return result;
- }
-
- }