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

📄 mymethod.java

📁 Struts框架实例(中文乱码解决
💻 JAVA
字号:
package meThod;

import java.sql.*;
import java.util.ArrayList;

import Bean.NewBean;
import MyDataSource.myDataSource;



public class Mymethod {
	private Connection con=null;
	private Statement  st =null;
 
	
	
	//查询方法
	public ArrayList sect(){
		ArrayList list=new ArrayList();
	try {
		con=myDataSource.getConnection();
		st = con.createStatement();
		ResultSet re = st.executeQuery("select id,title,content from news");

		while (re.next()) {
			NewBean bean = new NewBean();
			bean.setId(re.getString(1));
			bean.setTitle(re.getString(2));
			bean.setContent(re.getString(3));
			list.add(bean);

		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	finally{
		try {
			st.close();
			con.close();
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
	}
		return list;
	}
	
	//删除方法
public void del(int id){
 
		
		 
	 
	try {
		con=myDataSource.getConnection();
		st = con.createStatement();
		st.executeUpdate("delete from news where id="+id);

	 
	} catch (Exception e) {
		e.printStackTrace();
	}
	finally{
		try {
			st.close();
			con.close();
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
	}
		 
	}
 
}

⌨️ 快捷键说明

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