📄 gbcountdao.java
字号:
package com.netbar.dao;
import java.sql.*;
import java.util.*;
public class gbCountDao {
public gbCountDao() {
}
//获取当前页面访问次数。
public int getCurrentCount() {
Connection con = com.netbar.dao.databaseOprate.getConnection();
String sql = "select accessCount from gbCount";
PreparedStatement pstmt = null;
int count = 0;
try {
pstmt = con.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
count = rs.getInt(1);
}
rs.close();
pstmt.close();
con.close();
} catch (Exception ex) {
ex.printStackTrace();
return 0;
}
return count;
}
//获取管理员最后登陆时间
public String getTime(){
Connection con = com.netbar.dao.databaseOprate.getConnection();
String sql = "select lastAdminLoginTime from gbCount";
PreparedStatement pstmt = null;
String time="";
try {
pstmt = con.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
time = rs.getString(1);
}
rs.close();
pstmt.close();
con.close();
} catch (Exception ex) {
ex.printStackTrace();
return "";
}
return time;
}
//进入留言表界面时,让数据库中的accessCount值自增一次
public void updateCountWhenEnter(){
Connection con=com.netbar.dao.databaseOprate.getConnection();
PreparedStatement pstmt=null;
String sql="update gbCount set accessCount=accessCount+1 where gbCountID=1";
try {
pstmt=con.prepareStatement(sql);
pstmt.executeUpdate();
pstmt.close();
con.close();
} catch (Exception ex) {
System.out.println("更新留言表访问次数时失败。");
ex.printStackTrace();
}
}
public void updateTimeWhenLogin(){
Connection con=com.netbar.dao.databaseOprate.getConnection();
PreparedStatement pstmt=null;
// Date date=new Date();
//java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//String CurrentDate=sdf.format(new String());
String sql="update gbCount set lastAdminLoginTime=default where gbCountID=1";
try {
pstmt=con.prepareStatement(sql);
// pstmt.setDate(1,);
pstmt.executeUpdate();
pstmt.close();
con.close();
} catch (Exception ex) {
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -