📄 readeradd.java
字号:
content.add(btn1);
content.add(btn2);
content.add(btn7);
content.add(btn5);
content.add(btn6);
content.add(btn3);
content.add(btn4);
content.setBounds(0,0,480,435);
frame.setBounds(300,200,480,435);
frame.setResizable(false);
frame.setVisible(true);
}
public void itemStateChanged(ItemEvent es)
{if(es.getItemSelectable()==jtfd8)
{try{ View2();}
catch(SQLException eg){}
}
}
public void actionPerformed(ActionEvent e)
{str1=jtfd1.getText().trim();
str2=jtfd2.getText().trim();
str3=jtfd3.getText().trim();
str4=(String)jtfd4.getSelectedItem();
str5=(String)jtfd8.getSelectedItem();
str6=(String)jtfd10.getSelectedItem();
str7=jtfd5.getText().trim();
str8=jtfd6.getText().trim();
str9=jtfd7.getText().trim();
str10=jtfd9.getText().trim();
str11=jtfd11.getText().trim();
str12=jtfd12.getText().trim();
str13=jtfd13.getText().trim();
str14=jtfd14.getText().trim();
str17=jtfd15.getText().trim();
str16=jta.getText().trim();
str15=jtfd16.getText().trim();
Object obj=(JButton)e.getSource();
if(obj==btn1)//添加读者信息按钮
{ try{ Add();}
catch(SQLException eg){}
}
if(obj==btn5)//更新读者信息按钮
{ try{ Update1();}
catch(SQLException eg){}
}
if(obj==btn6)
{new ReaderU(this); }
if(obj==btn2)//删除读者信息按钮
{ try{ Delete();}
catch(SQLException eg){}
}
if(obj==btn7)
{ new ReaderD(this);}
if(obj==btn3)
{jtfd1.setText("");jtfd2.setText("");jtfd3.setText("");
jtfd5.setText("");jtfd6.setText("");jtfd7.setText("");
jtfd9.setText("");jtfd11.setText("");jtfd12.setText("");
jtfd13.setText("");jtfd14.setText("");jtfd15.setText("");
jtfd16.setText("");jta.setText("");
}
if(obj==btn4)
{frame.dispose();}
}
////////////////////////////////查询读者类型中的类型名称代码///////////////////////////////////////////////
public void View() throws SQLException
{
try{
String strurl =
"jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DataBase/Library.mdb";
try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch (ClassNotFoundException eg) {}
con= DriverManager.getConnection(strurl);
Statement stmt= con.createStatement();
ResultSet rs = stmt.executeQuery("select * from 读者类型 ORDER BY 编号");
while(rs.next())
{String bianhao=rs.getString(1);
String typename=rs.getString(2);
jtfd8.addItem(typename);
}
con.close();
}
catch(Exception es)
{es.printStackTrace();}
}
////////////////////////////////查询读者类型中的可借数量和最长期限代码///////////////////////////////////////////////
public void View2() throws SQLException
{
try{
String strurl =
"jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DataBase/Library.mdb";
try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch (ClassNotFoundException eg) {}
con= DriverManager.getConnection(strurl);
Statement stmt= con.createStatement();
ResultSet rs = stmt.executeQuery("select * from 读者类型 ORDER BY 编号");
while(rs.next())
{String bianhao=rs.getString(1);
String typename=rs.getString(2);
String count=rs.getString(3);
String date=rs.getString(4);
if(typename.equals(jtfd8.getSelectedItem()))
{jtfd14.setText(count);jtfd15.setText(date);}
}
con.close();
}
catch(Exception es)
{es.printStackTrace();}
}
////////////////////////////////查询有效证件代码///////////////////////////////////////////////
public void View1() throws SQLException
{
try{
String strurl =
"jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DataBase/Library.mdb";
try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch (ClassNotFoundException eg) {}
con= DriverManager.getConnection(strurl);
Statement stmt= con.createStatement();
ResultSet rs = stmt.executeQuery("select * from 有效证件 ORDER BY 编号");
while(rs.next())
{String bianhao=rs.getString(1);
String typename=rs.getString(2);
jtfd10.addItem(typename);
}
con.close();
}
catch(Exception es)
{es.printStackTrace();}
}
////////////////////////////////添加读者代码///////////////////////////////////////////////
public void Add() throws SQLException
{
String strurl =
"jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DataBase/Library.mdb";
try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch (ClassNotFoundException es) {}
con= DriverManager.getConnection(strurl);
Statement stmt = con.createStatement();
if(str1.equals("")|str2.equals("")|str3.equals("")|str4.equals("")|str5.equals(""))
{ JOptionPane.showMessageDialog(frame,"各项不能为空!");
return;
}
else if(str6.equals("")|str7.equals("")|str8.equals("")|str9.equals("")|str10.equals(""))
{ JOptionPane.showMessageDialog(frame,"各项不能为空!");
return;
}
else if(str11.equals("")|str12.equals("")|str13.equals("")|str14.equals("")|str15.equals("")|str16.equals("")|str17.equals(""))
{ JOptionPane.showMessageDialog(frame,"各项不能为空!");
return;
}
else { ResultSet rs = stmt.executeQuery("select * from 读者资料 where 读者编号='" + str2 + "'OR 条形码='"+str3+"'");
if(rs.next())
{ JOptionPane.showMessageDialog(null, "此读者编号或条形码已存在,请您重新输入!", "警告",JOptionPane.WARNING_MESSAGE);
jtfd2.setText("");
jtfd3.setText("");
}
else
{ stmt.executeUpdate("INSERT INTO 读者资料(读者姓名,读者编号,条形码,性别,身份,有效证件,证件号码,注册日期,截止日期,出生日期,联系电话,联系地址,读者状态,可借数量,最长期限,操作员,备注) values ('"+str1+"','"+str2+"','"+str3+"','"+str4+"','"+str5+"','"+str6+"','"+str7+"','"+str8+"','"+str9+"','"+str10+"','"+str11+"','"+str12+"','"+str13+"','"+str14+"','"+str17+"','"+str15+"','"+str16+"')");
JOptionPane.showMessageDialog(null, "恭喜您添加新读者成功!");
try{ reader.setnull();}
catch(SQLException ed){}
try{ reader.view();}
catch(SQLException ed){}
}
}
con.close();
}
////////////////////////////////更新读者代码///////////////////////////////////////////////
public void Update1() throws SQLException
{
String strurl =
"jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DataBase/Library.mdb";
try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch (ClassNotFoundException es) {}
con= DriverManager.getConnection(strurl);
Statement stmt = con.createStatement();
if(str1.equals("")|str2.equals("")|str3.equals("")|str4.equals("")|str5.equals(""))
{ JOptionPane.showMessageDialog(frame,"各项不能为空!");
return;
}
else if(str6.equals("")|str7.equals("")|str8.equals("")|str9.equals("")|str10.equals(""))
{ JOptionPane.showMessageDialog(frame,"各项不能为空!");
return;
}
else if(str11.equals("")|str12.equals("")|str13.equals("")|str14.equals("")|str15.equals("")|str16.equals("")|str17.equals(""))
{ JOptionPane.showMessageDialog(frame,"各项不能为空!");
return;
}
else { ResultSet rs = stmt.executeQuery("select * from 读者资料 ");
if(rs.next())
{
stmt.executeUpdate("update 读者资料 set 读者姓名='"+str1+"',性别='"+str4+"',身份='"+str5+"',有效证件='"+str6+"',证件号码='"+str7+"',注册日期='"+str8+"',截止日期='"+str9+"',出生日期='"+str10+"',联系电话='"+str11+"',联系地址='"+str12+"',读者状态='"+str13+"',可借数量='"+str14+"',最长期限='"+str17+"',操作员='"+str15+"',备注='"+str16+"'where 条形码='"+str3+"'");
JOptionPane.showMessageDialog(null, "恭喜您更新读者资料成功!");
try{ reader.setnull();}
catch(SQLException ed){}
try{ reader.view();}
catch(SQLException ed){}
}
}
con.close();
}
////////////////////////////////删除读者代码///////////////////////////////////////////////
public void Delete() throws SQLException
{
String strurl =
"jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DataBase/Library.mdb";
try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch (ClassNotFoundException es) {}
con= DriverManager.getConnection(strurl);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from 读者资料 ");
if(rs.next())
{if(JOptionPane.showConfirmDialog(reader, "确实要删除该读者的所有信息吗?\n删除的信息将不能恢复,是否继续?","删除确定", JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE) == 0)
{stmt.executeUpdate("delete from 读者资料 where 条形码='"+str3+"'");
JOptionPane.showMessageDialog(null, "读者资料删除成功!");
}
try{ reader.setnull();}
catch(SQLException ed){}
try{ reader.view();}
catch(SQLException ed){}
}
con.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -