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

📄 firstlevertitledao.java

📁 新闻系统的具体的一块
💻 JAVA
字号:
package dao;
import java.sql.*;
import java.text.*;
import java.util.*;
import entity.NewsFirstLeverTitle;

public class FirstLeverTitleDao {
	public int insertOneTitle(NewsFirstLeverTitle title){
		int rows=0;
		Connection conn=ConnectionManager.getConnection();		
		PreparedStatement pStatement=null;
		try{
			SimpleDateFormat hmFormat=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
			String sql="insert into FirstLeverTitle values(?,?,?)";
			pStatement=conn.prepareStatement(sql);
//			pStatement.setInt(1, 1);
			pStatement.setString(1,title.getTitleName());
			pStatement.setString(2,title.getCreator());
			pStatement.setString(3,hmFormat.format(new java.util.Date()));
//			pStatement.setString(4,"2008");
			rows=pStatement.executeUpdate();
//			pStatement.close();
//			conn.close();
		} catch(SQLException e){
			e.printStackTrace();
		}finally{
			ConnectionManager.closeAll(null,pStatement,conn);
		}
		return rows;
	}
	public List getAllFirstLeverTitleList(){
		ArrayList list=new ArrayList();
		ResultSet res=null;
		Connection dbConnection=null;		
		PreparedStatement pStatement=null;
		try{
			dbConnection=ConnectionManager.getConnection();
			String sql="select * from FirstLeverTitle order by CreatTime desc";
			pStatement=dbConnection.prepareStatement(sql);
			res=pStatement.executeQuery();
			while(res.next()){
				int id=res.getInt("Id");
				String title=res.getString("TitleName");
				String creator=res.getString("Creator");
				java.util.Date time=res.getDate("CreatTime");
				NewsFirstLeverTitle fTitle=new NewsFirstLeverTitle(id,title,creator,time);
				list.add(fTitle);
			}
		}catch(SQLException e){
			e.printStackTrace();
		}finally{
			ConnectionManager.closeAll(null,pStatement,dbConnection);
		}
		return list;
	}
//	public int insertOneTitle(String title){
//		int rows=0;
//		Connection conn=ConnectionManager.getConnection();		
//		PreparedStatement pStatement=null;
//		try{
//			SimpleDateFormat hmFormat=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//			String sql="insert into FirstLeverTitle values(?,?,?)";
//			pStatement=conn.prepareStatement(sql);
//			pStatement.setInt(1, 1);
//			pStatement.setString(1,title);
//			pStatement.setString(2,"管理员");
//			pStatement.setString(3,hmFormat.format(new java.util.Date()));
//			pStatement.setString(4,"2008");
//			rows=pStatement.executeUpdate();
//			pStatement.close();
//			conn.close();
//		} catch(SQLException e){
//			e.printStackTrace();
//		}finally{
//			ConnectionManager.closeAll(null,pStatement,conn);
//		}
//		return rows;
//	}
//	public static void main(String []args){
//		NewsFirstLeverTitle title=new NewsFirstLeverTitle();
//		title.setCreator("zhangsan");
//		title.setTitleName("title1");
//		FirstLeverTitleDao test=new FirstLeverTitleDao();
//		test.insertOneTitle(title);
//	}
}

⌨️ 快捷键说明

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