📄 creditdao.java
字号:
package com.dao;
import com.tool.JDBConnection;
import java.util.*;
import com.domain.CreditVO;
import java.sql.*;
public class CreditDao {
private JDBConnection connection = null;
public CreditDao() {
connection = new JDBConnection();
this.connection.creatConnection(); //利用构造方法调用类中的对象对数据库创建连接
}
public List creditSelect() {
List list = new ArrayList();
CreditVO credit = null;
String sql = "select * from tb_credit order by id";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
credit = new CreditVO();
credit.setId(Integer.valueOf(rs.getString(1)));
credit.setCredit_number(rs.getString(2));
credit.setCredit_name(rs.getString(3));
credit.setCredit_remark(rs.getString(4));
list.add(credit);
}
}
catch (SQLException ex) {
}
connection.closeConnection();
return list;
}
public CreditVO creditSelectOne(String number) {
CreditVO credit = null;
String sql = "select * from tb_credit where credit_number='" + number + "'";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
credit = new CreditVO();
credit.setId(Integer.valueOf(rs.getString(1)));
credit.setCredit_number(rs.getString(2));
credit.setCredit_name(rs.getString(3));
credit.setCredit_remark(rs.getString(4));
}
}
catch (SQLException ex) {
}
connection.closeConnection();
return credit;
}
//以名称为条件查询
public CreditVO creditSelectName(String name) {
CreditVO credit = null;
String sql = "select * from tb_credit where credit_name='" + name + "'";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
credit = new CreditVO();
credit.setId(Integer.valueOf(rs.getString(1)));
credit.setCredit_number(rs.getString(2));
credit.setCredit_name(rs.getString(3));
credit.setCredit_remark(rs.getString(4));
}
}
catch (SQLException ex) {
}
connection.closeConnection();
return credit;
}
//添加操作
public void creditInsert(CreditVO vo) {
String sql = "insert into tb_credit values ('" + vo.getCredit_number() + "','" +
vo.getCredit_name() + "','" + vo.getCredit_remark() + "')";
connection.executeUpdate(sql);
connection.closeConnection();
}
//删除操作
public void creditDelete(Integer id) {
String sql = "delete from tb_credit where id='" + id + "'";
connection.executeUpdate(sql);
connection.closeConnection();
}
//修改编号的操作
public void creditUpdateNumber(Integer id, String number) {
String unNumber = "Credit-" + String.valueOf(id);
String sql = "update tb_credit set credit_number='" + unNumber +
"' where credit_number='" + number + "'";
connection.executeUpdate(sql);
connection.closeConnection();
}
//修改操作
public void creditUpdate(CreditVO vo) {
String sql = "update tb_credit set credit_name='" + vo.getCredit_name() +
"',credit_remark='" + vo.getCredit_remark() + "' where credit_number='" +
vo.getCredit_number() + "'";
connection.executeUpdate(sql);
connection.closeConnection();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -