📄 publishdao.java
字号:
package com.DAO;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import com.VO.PublishInfoVO;
import com.VO.UserVO;
import com.database.DBAccess;
import com.exception.DataBaseException;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class PublishDAO {
// public static void main(String ags[]){
//
// PublishDAO d=new PublishDAO();
// String[] f=d.findPublishName();
// for (int i=0;i<f.length;i++){
// System.out.println(f[i]);
// }
////// PublishInfoVO g=d.find("电子工业出版社");
////// System.out.println(g.getPubName());
////
//// DBAccess db=null;
//// String pubID=null;
//// try {
//// db=DBAccess.getDBAccess();
//// Connection con=db.getConnection();
//// CallableStatement cstmt=con.prepareCall("{?=call pro_pubID()}");
//// //注册返回值类型
//// cstmt.registerOutParameter(1,Types.VARCHAR);
//// cstmt.execute();
//// //得到返回值
//// String flag=cstmt.getString(1);
//// System.out.println(flag);
//// cstmt.close();
//// } catch (SQLException e1) {
//// // TODO 自动生成 catch 块
//// e1.printStackTrace();
//// }catch (DataBaseException e1) {
//// // TODO 自动生成 catch 块
//// e1.printStackTrace();
//// }
// }
/**
* @param pubname
* @return 返回一个对象
* 功能: 根据出版社名查找满足条件的记录
*/
public PublishInfoVO find(String pubname){
String strsql="select * from publishInfo where pubName='"+pubname+"'";
PublishInfoVO user=null;
DBAccess db;
try {
db = DBAccess.getDBAccess();
db.getConnection();
ResultSet ret=db.query(strsql);
try {
while (ret.next()){
user=new PublishInfoVO();
user.setPubID(ret.getString(1));
user.setPubName(ret.getString(2));
user.setPubAdress(ret.getString(3));
user.setPubPhone(ret.getString(4));
user.setPubEmail(ret.getString(5));
}
} catch (SQLException e) {
e.printStackTrace();
}
} catch (DataBaseException e1) {
e1.printStackTrace();
}finally{
// db.close();
}
return user;
}
/**
* @return 返回一个数组对象
* 功能 :查找所有的记录
*/
public ArrayList findAll(){
String strsql="select * from publishInfo";
ArrayList list=new ArrayList();
DBAccess db;
try {
db = DBAccess.getDBAccess();
db.getConnection();
ResultSet ret=db.query(strsql);
try {
while (ret.next()){
PublishInfoVO user=new PublishInfoVO();
user.setPubID(ret.getString(1));
user.setPubName(ret.getString(2));
user.setPubAdress(ret.getString(3));
user.setPubPhone(ret.getString(4));
user.setPubEmail(ret.getString(5));
list.add(user);
}
} catch (SQLException e) {
e.printStackTrace();
}
} catch (DataBaseException e1) {
e1.printStackTrace();
}finally{
// db.close();
}
return list;
}
/**
* @param publish
* @return int (添加失败返回0)
* 功能: 插入操作 (一次插入一条记录)
*/
public int insert(PublishInfoVO publish){
int flag=0;
String sql="insert into publishInfo values('"+publish.getPubID()+"','"+publish.getPubName()+"','"+publish.getPubAdress()+"','"+publish.getPubPhone()+"','"+publish.getPubEmail()+"')";
// System.out.println(sql);
DBAccess db;
try {
db=DBAccess.getDBAccess();
flag=db.update(sql);
} catch (DataBaseException e) {
e.printStackTrace();
}finally{
// db.close();
}
return flag;
}
/**
* @param oldPublishName (出版社名)
* @return (删除失败返回0)
* 功能:删除操作 (删除满足条件的记录)
*/
public int delete(String oldPublishName){
int flag=0;
String sql="delete from publishInfo where pubName='"+oldPublishName+"'";
// System.out.println(sql);
DBAccess db;
try {
db = DBAccess.getDBAccess();
db.getConnection();
flag=db.update(sql);
} catch (DataBaseException e) {
e.printStackTrace();
}finally{
// db.close();
}
return flag;
}
public int update(PublishInfoVO publish){
int flag=0;
String sql="update publishInfo set pubAdress='"+publish.getPubAdress()+"',pubPhone='"+publish.getPubPhone()+"',pubEmail='"+publish.getPubEmail()+"' where pubName='"+publish.getPubName()+"'";
// System.out.println(sql);
DBAccess db;
try {
db = DBAccess.getDBAccess();
db.getConnection();
flag=db.update(sql);
} catch (DataBaseException e) {
e.printStackTrace();
}finally{
// db.close();
}
return flag;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -