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

📄 typem.java

📁 新闻管理系统实现对新闻添加修改删除外挂了一个用户的注册还有一个外挂的投票
💻 JAVA
字号:
package com.vsked.services;

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

import java.util.ArrayList;


import com.vsked.javaBean.Typest;
import com.vsked.models.ConnectDB;


//类型方法集合
public class Typem {
	
	private Connection conn=null;
	private PreparedStatement pt=null;
	private ResultSet rs=null;
	//表示查询结果集合的对象
	private ArrayList results=null;
	private Typest types=null;
	private boolean flag=false;
	
	
	//添加新闻类别
	public boolean addTypes(String typ){
		conn=ConnectDB.getConnectionJDBC();
	    try {
			pt=conn.prepareStatement("insert into typest values(?)");
			pt.setString(1,typ);			
			pt.execute();
			flag=true;			
		} catch (Exception e) {
		
		}finally{
			ConnectDB.close();
		}
		
		return flag;
	}
	
	//修改新闻类别
	public boolean modifyTypesById(Typest typ){
		conn=ConnectDB.getConnectionJDBC();
	    try {
			pt=conn.prepareStatement("update typest set typename=? where typeid=?");
			pt.setString(1,typ.getTypename());	
			pt.setInt(2, typ.getTypeid());
			int num=pt.executeUpdate();
			if(num>0){
				flag=true;	
			}								
		} catch (Exception e) {
		
		}finally{
			ConnectDB.close();
		}
		
		return flag;
	}
	
	
//	根据编号删除类型
	public boolean deleteTypesById(int id){
		conn=ConnectDB.getConnectionJDBC();
	    try {
			pt=conn.prepareStatement("delete typest where typeid=?");
			pt.setInt(1,id);
			int num=pt.executeUpdate();
			if(num>0){
				flag=true;	
			}					
		} catch (Exception e) {
		
		}finally{
			ConnectDB.close();
		}
		
		return flag;
	}
	//查询所有类型
	public ArrayList getAllTypeInfo(){
		results=new ArrayList();
		conn=ConnectDB.getConnectionJDBC();
	    try {
			pt=conn.prepareStatement("select * from typest order by typeid ");			
			rs=pt.executeQuery();	
			while (rs.next()) {
				results.add(new Typest(rs.getInt(1),rs.getString(2)));				
			}
		} catch (Exception e) {
		
		}finally{
			ConnectDB.close();
		}
		
		return results;
	}
	//查询类型数量
	public int getTypeCount(){
		int count=0;
		conn=ConnectDB.getConnectionJDBC();
	    try {
			pt=conn.prepareStatement("select count(*) from typest");			
			rs=pt.executeQuery();	
			if(rs.next()) {
				count=rs.getInt(1);			
			}
		} catch (Exception e) {
		
		}finally{
			ConnectDB.close();
		}
		
		return count;
	}
	
//	查询类型数量
	public String getTypeName(int id){
		String typename="";
		conn=ConnectDB.getConnectionJDBC();
	    try {
			pt=conn.prepareStatement("select typename from typest where typeid=?");	
			pt.setInt(1, id);
			rs=pt.executeQuery();	
			if(rs.next()) {
				typename=rs.getString(1);	
			}
		} catch (Exception e) {
		
		}finally{
			ConnectDB.close();
		}
		
		return typename;
	}

}

⌨️ 快捷键说明

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