📄 classofpets.java~5~
字号:
package com.richard.dao;
import java.util.*;
import com.richard.dao.*;
import com.richard.dto.*;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
public class ClassOfPets implements InterfaceOfPets {
DBOperate objDBOperate = new DBOperate();
public ClassOfPets() {
}
/**
* PetsQueryAll
*
* @return ArrayList
* @todo Implement this com.richard.dao.InterfaceOfPets method
*/
public ArrayList PetsQueryAll(int perPage, int pageNumber) {
ArrayList objArrayList = new ArrayList();
String sqlCommand = "{call proc_pets (?,?)}";
try {
CallableStatement cs = objDBOperate.getConnect("petclinic").
prepareCall(sqlCommand);
cs.setInt(1, perPage);
cs.setInt(2, pageNumber);
ResultSet rs = cs.executeQuery();
while (rs.next()) {
Pets objPets = new Pets();
objPets.setId(rs.getInt(1));
objPets.setName(rs.getString(2));
objPets.setBirth_date(rs.getString(3));
objPets.setType_id(rs.getInt(4));
objPets.setOwner_id(rs.getInt(5));
objArrayList.add(objPets);
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
return objArrayList;
}
/**
* petsDelete
*
* @param objPets Pets
* @todo Implement this com.richard.dao.InterfaceOfPets method
*/
public void petsDelete(Pets objPets) {
int petsId=objPets.getId();
String sqlCommand="delete from pets where id='"+petsId+"'";
try
{
objDBOperate.exeSql("petclinic",sqlCommand);
}catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
/**
* petsInsert
*
* @param objPets Pets
* @todo Implement this com.richard.dao.InterfaceOfPets method
*/
public void petsInsert(Pets objPets) {
String petName=objPets.getName();
String petBirthday=objPets.getBirth_date();
int typeId=objPets.getType_id();
int ownerId=objPets.getOwner_id();
String sqlCommand="insert into pets (name,birth_date,type_id,owner_id) values(?,?,?,?)";
try
{
PreparedStatement ps=objDBOperate.getPreparedStatement("petclinic",sqlCommand);
ps.setString(1,petName);
ps.setString(2,petBirthday);
ps.setInt(3,typeId);
ps.setInt(4,ownerId);
ps.execute();
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
/**
* petsQuery
*
* @param objPets Pets
* @return Pets
* @todo Implement this com.richard.dao.InterfaceOfPets method
*/
public Pets petsQuery(Pets objPets) {
return null;
}
/**
* petsUpdate
*
* @param objPets Pets
* @todo Implement this com.richard.dao.InterfaceOfPets method
*/
public void petsUpdate(Pets objPets) {
}
public int totalPages()
{
int totalPages = 0;
String sqlCommand = "select count(*) from pets";
try {
PreparedStatement objStatement = objDBOperate.getPreparedStatement(
"petclinic", sqlCommand);
ResultSet rs = objStatement.executeQuery();
while (rs.next()) {
totalPages = rs.getInt(1);
}
} catch (Exception ex) {
System.out.println("错误提示:" + ex.getMessage());
}
if (totalPages % 15 == 0) {
return totalPages / 15;
} else {
return (totalPages / 15) + 1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -