📄 countdao.java
字号:
package com.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import com.tool.JDBConnection;
import java.sql.*;
import com.actionForm.AcountForm;
public class CountDao {
private String insert =
"insert into tb_count values (?,?,?,?,?,?,?,?)";
private String selectOne = "select * from tb_count where account=?";
private String add =
"update tb_count set number=number+1 where account=?";
private Connection connection = null; //定义连接的对象
private PreparedStatement ps = null; //定义预准备的对象
private JDBConnection jdbc = null; //定义数据库连接对象
public CountDao() {
jdbc = new JDBConnection();
connection = jdbc.connection; //利用构造方法取得数据库连接
}
//====================================================================
public void addCount(String account) {
try {
ps = connection.prepareStatement(this.add);
ps.setString(1, account);
ps.executeUpdate();
ps.close();
} catch (SQLException ex) {
}
}
//=====================================================
public AcountForm selectOneAcount(String account) {
AcountForm form = null;
try {
ps = connection.prepareStatement(this.selectOne);
ps.setString(1, account);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
form = new AcountForm();
form.setId(rs.getInt(1));
form.setAccount(rs.getString(2));
form.setPassword(rs.getString(3));
form.setName(rs.getString(4));
form.setAge(rs.getInt(5));
form.setSex(rs.getString(6));
form.setBorn(rs.getString(7));
form.setProfession(rs.getString(8));
form.setNumber(rs.getInt(9));
ps.close();
}
} catch (SQLException ex) {
}
return form;
}
//================================================================
public void insertCount(AcountForm form){
try {
ps = connection.prepareStatement(this.insert);
ps.setString(1,form.getAccount());
ps.setString(2,form.getPassword());
ps.setString(3,form.getName());
ps.setInt(4,form.getAge());
ps.setString(5,form.getSex());
ps.setString(6,form.getBorn());
ps.setString(7,form.getProfession());
ps.setInt(8,form.getNumber());
ps.executeUpdate();
ps.close();
} catch (SQLException ex) {
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -