📄 yy.java
字号:
package program;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class YY {
public YY(String bclass,String bno,String bcount) throws NumberFormatException, ClassNotFoundException, SQLException
{
work(bclass,bno,Integer.parseInt(bcount));
}
public void work(String bclass,String bno,int bcount) throws ClassNotFoundException, SQLException
{
String DBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String connectionStr="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)}; DBQ=D:/Java_Work/BookManager/program/db/bookmanage.mdb";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
int kucun,sheng;
Getdate now =new Getdate();
Class.forName(DBDriver); //加载驱动器
con=DriverManager.getConnection(connectionStr,"",""); //连接数据库
stmt=con.createStatement(); //创建Statement对象
stmt.executeUpdate("INSERT INTO 出库(书号,数量,日期,班号) VALUES " +
"('"+bno+"',"+bcount+",'"+now.Getdate()+"',"+"'"+bclass+"')");
// 添加出库表
rs=stmt.executeQuery("select * from 库存 where 书号='"+bno+"'");
if(rs.next())
{
kucun=rs.getInt("数量");
sheng=kucun-bcount;
if(sheng>0)
stmt.executeUpdate("update 库存 set 数量="+sheng+" where 书号='"+bno+"'");
if(sheng==0)
stmt.executeUpdate("delete from 库存 where 书号='"+bno+"'");
}
// 从库存中减去bcount 如结果为零,则删除该条
rs=stmt.executeQuery("select * from 订_inf where 书号='"+bno+"' and 班号='"+bclass+"'");
if(rs.next())
{
stmt.executeUpdate("delete from 订_inf where 书号='"+bno+"' and 班号='"+bclass+"'");
}
// 如订_inf中有该班订书的信息,则删除
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -