📄 secondlevertitledao.java
字号:
package dao;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import entity.*;
public class SecondLeverTitleDao {
public int insertTwoTitle(NewsSecondLeverTitle 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 SecondLeverTitle(TitleName,FilePath,Creator,CreateTime,ParentTitle) values(?,?,?,?,?)";
pStatement=conn.prepareStatement(sql);
pStatement.setString(1,title.getTitleName());
pStatement.setString(2,title.getFilePath());
pStatement.setString(3,title.getCreator());
pStatement.setString(4,hmFormat.format(new java.util.Date()));
pStatement.setInt(5,title.getParentTitle());
rows=pStatement.executeUpdate();
} catch(SQLException e){
e.printStackTrace();
}finally{
ConnectionManager.closeAll(null,pStatement,conn);
}
return rows;
}
public List getSecondLeverTitleListByFirstLeverTitle(int one){
ArrayList list=new ArrayList();
ResultSet res=null;
Connection dbConnection=null;
PreparedStatement pStatement=null;
try{
dbConnection=ConnectionManager.getConnection();
String sql="select * from SecondLeverTitle where ParentTitle="+one+" order by CreateTime desc";
pStatement=dbConnection.prepareStatement(sql);
res=pStatement.executeQuery();
while(res.next()){
int id=res.getInt("Id");
String title=res.getString("TitleName");
String filePath=res.getString("FilePath");
String creator=res.getString("Creator");
java.util.Date time=res.getDate("CreateTime");
int parentId=res.getInt("ParentTitle");
NewsSecondLeverTitle sTitle=new NewsSecondLeverTitle(id,title,filePath,creator,time,parentId);
list.add(sTitle);
}
}catch(SQLException e){
e.printStackTrace();
}finally{
ConnectionManager.closeAll(null,pStatement,dbConnection);
}
return list;
}
// public static void main(String []args){
// NewsSecondLeverTitle title=new NewsSecondLeverTitle();
// title.setTitleName("xinwen");
// title.setCreator("bianji");
// title.setFilePath("C:\\");
// title.setParentTitle(1);
// SecondLeverTitleDao test=new SecondLeverTitleDao();
// test.insertTwoTitle(title);
// List l=test.getSecondLeverTitleListByFirstLeverTitle(4);
// for(int i=0;i<l.size();i++){
// NewsSecondLeverTitle sec=(NewsSecondLeverTitle)l.get(i);
// System.out.println(sec.getTitleName());
// }
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -