📄 billdeptdao.java
字号:
package dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import po.VendorPO;
import vo.*;
public class billdeptDAO {
Connection conn=null;
Statement state=null;
ResultSet rs=null;
//查询所有
public ArrayList findAll()
{
ArrayList al=new ArrayList();
try {
conn=Tools.getConnection();
state=conn.createStatement();
//System.out.println("select * from Table_Bill_Item,Table_dept where Table_Bill_Item.Dept_id=Table_dept.Dept_id");
rs=state.executeQuery("select * from Table_Bill_Item,Table_dept where Table_Bill_Item.Dept_id=Table_dept.Dept_id");
while(rs.next())
{
billdeptVO bdvo=new billdeptVO();
bdvo.setBill_Item_ID(rs.getInt("Bill_ID"));
bdvo.setBill_ID(rs.getInt("Bill_Item_ID"));
bdvo.setBill_Item_Expense(rs.getInt("Bill_Item_Expense"));
bdvo.setDeptname(rs.getString("deptname"));
al.add(bdvo);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
if(rs != null)
rs.close();
if(state != null)
state.close();
if(conn != null)
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return al;
}
//得到ID
public int getNextID()
{
billdeptVO bdvo=new billdeptVO();
int myID=0;
conn = Tools.getConnection();
try {
state=conn.createStatement();
rs=state.executeQuery("select max(Bill_Item_ID) myID from Table_Bill_Item");
if(bdvo.getBill_Item_ID()==0)
{
myID=1000000001;
}
else
{
if(rs.next())
{
myID = rs.getInt("myID");
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
if(rs!=null)
rs.close();
if(state!=null)
state.close();
if(conn!=null)
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return ++myID;
}
//插入一条
public boolean Addbilldept(billdeptVO vm)
{
boolean isOK=false;
try {
conn=Tools.getConnection();
state=conn.createStatement();
int i = state.executeUpdate("insert into Table_Bill_Item values("+vm.getBill_ID()+","+vm.getDept_id()+","+vm.getBill_Item_ID()+","+vm.getBill_Item_Expense()+")");
if(i>0)
{
isOK=true;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
if(state!=null)
state.close();
if(conn!=null)
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return isOK;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -