📄 firstlevetitledbopreation.java
字号:
package com.jbaptech.accp.newspublish.db;
import com.jbaptech.accp.newspublish.data.FirstLevelTitle;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
/**
* FirstLeveTitleDbOpreation.
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class FirstLeveTitleDbOpreation {
/**
* constructor.
*/
public FirstLeveTitleDbOpreation() {
}
/**
* get all first level title list.
* @return ArrayList
*/
public ArrayList getAllFirstLevelTitleList() {
ArrayList list = new ArrayList();
Connection dbConnection = null;
PreparedStatement pStatement = null;
ResultSet res = null;
try {
dbConnection = ConnectionManager.getConnction();
// 查询数据SQL语句
String strSql =
"select * from FirstLevelTitle order by CreatTime desc";
//查询操作
pStatement = dbConnection.prepareStatement(strSql);
res = pStatement.executeQuery();
while (res.next()) {
FirstLevelTitle fTitle = new FirstLevelTitle();
fTitle.setId(res.getInt("id"));
fTitle.setTitleName(res.getString("TitleName"));
fTitle.setCreater(res.getString("Creater"));
fTitle.setCreateTime(res.getDate("CreatTime"));
list.add(fTitle);
}
} catch (SQLException sqlE) {
sqlE.printStackTrace();
} finally {
ConnectionManager.closeResultSet(res);
ConnectionManager.closeStatement(pStatement);
ConnectionManager.closeConnection(dbConnection);
}
return list;
}
/**
* insert a row into FirstLevelTitle table.
* @param fTitle FirstLevelTitle
* @return int
*/
public int insertOneRecord(FirstLevelTitle fTitle) {
int result = 0;
Connection con = null;
PreparedStatement pStatement = null;
try {
Date currentTime = new Date();
SimpleDateFormat HMFromat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String strCurrentTime = HMFromat.format(currentTime);
con = ConnectionManager.getConnction();
String strSql =
"insert into FirstLevelTitle values(?,?,?,?)";
pStatement = con.prepareStatement(strSql);
pStatement.setInt(1, getNewId());
pStatement.setString(2, fTitle.getTitleName());
pStatement.setString(3, fTitle.getCreater());
pStatement.setString(4, strCurrentTime);
result = pStatement.executeUpdate();
} catch (SQLException sqlE) {
sqlE.printStackTrace();
} finally {
ConnectionManager.closeStatement(pStatement);
ConnectionManager.closeConnection(con);
}
return result;
}
/**
* create a new id of FirstLevelTitle.
* @return int
*/
private int getNewId() {
int id = 0;
Connection con = null;
PreparedStatement pstmt = null;
ResultSet resSet = null;
try {
con = ConnectionManager.getConnction();
// 查询数据SQL语句
String sqlStr = "select max(id) from FirstLevelTitle ";
//查询操作
pstmt = con.prepareStatement(sqlStr);
resSet = pstmt.executeQuery();
if (resSet.next()) {
id = resSet.getInt(1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
ConnectionManager.closeResultSet(resSet);
ConnectionManager.closeStatement(pstmt);
ConnectionManager.closeConnection(con);
}
return id + 1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -