📄 jdbc.java
字号:
JLabel Ibview7=new JLabel("固定电话:");
Ibview7.setFont(new Font("宋体",Font.BOLD,14));
TextField tx16=new TextField(15);
tx16.setText(""+FixedTele);
myP.add(Ibview7);
myP.add(tx16);
win1.setVisible(true);
JLabel Ibview8=new JLabel("手机: ");
Ibview8.setFont(new Font("宋体",Font.BOLD,14));
TextField tx17=new TextField(15);
tx17.setText(""+MobilePhone);
myP.add(Ibview8);
myP.add(tx17);
win1.setVisible(true);
}
cs.close();
con.close();
}
catch(SQLException e)
{
System.out.println("SQLException caught");
}
catch(ClassNotFoundException ex)
{
System.out.println("error");
}
}
public void takeMoney(int money)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(url);
CallableStatement cs=con.prepareCall("{call query1(?)}");
cs.setString(1,CardNum);
ResultSet rs=cs.executeQuery();
while(rs.next())
{
int Remains=rs.getInt("Remains");
int CreditQuant=rs.getInt("CreditQuant");
int limitCQ =(int) (0.7 * CreditQuant + Remains);
if(money<=Remains)
{
/* CallableStatement cs1=con.prepareCall("{call query2(?)}");
cs1.setInt(1,money);
cs1.executeUpdate();
cs1.close();*/
PreparedStatement ps=con.prepareStatement
("UPDATE Cardinfo SET Cardinfo.Remains = Cardinfo.Remains-? WHERE Cardinfo.CardNum = ?");
ps.setInt(1,money);
ps.setString(2,CardNum);
ps.executeUpdate();
ps.close();
myP.removeAll();
JLabel money1=new JLabel("交易成功!");
money1.setFont(new Font("宋体",Font.BOLD,24));
money1.setForeground(Color.BLUE);
myP.add(money1);
win1.setVisible(true);
}
else if(money <= limitCQ)
{
/*CallableStatement cs2=con.prepareCall("{call quary5(?)}");
cs2.setInt(1,money);
cs2.executeUpdate();
cs2.close();*/
PreparedStatement ps2=con.prepareStatement
("UPDATE Cardinfo SET Cardinfo.CreditQuant = Cardinfo.CreditQuant+Cardinfo.Remains-?,Cardinfo.Remains = 0 WHERE Cardinfo.CardNum = ?"
);
ps2.setInt(1,money+((int)((long)money*0.003-1)+1));
ps2.setString(2,CardNum);
ps2.executeUpdate();
ps2.close();
myP.removeAll();
JLabel money2=new JLabel("交易成功!");
money2.setFont(new Font("宋体",Font.BOLD,24));
money2.setForeground(Color.BLUE);
myP.add(money2);
win1.setVisible(true);
}
else {
myP.removeAll();
JLabel money4=new JLabel("交易失败!!");
money4.setFont(new Font("宋体",Font.BOLD,24));
money4.setForeground(Color.RED);
myP.add(money4);
win1.setVisible(true);}
}
//cs1.close();
cs.close();
con.close();
}
catch(SQLException e)
{
balance();
}
catch(ClassNotFoundException ex)
{
System.out.println("error");
}
}
public void updatePassword(int pass)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(url);
CallableStatement cs=con.prepareCall("{call query1(?)}");
cs.setString(1,CardNum);
ResultSet rs=cs.executeQuery();
while(rs.next())
{
/* CallableStatement cs2=con.prepareCall("{call query3(?)}");
cs2.setInt(1,pass);
cs2.executeUpdate();
cs2.close();*/
PreparedStatement ps=con.prepareStatement
("UPDATE Cardinfo SET Cardinfo.password = ? WHERE Cardinfo.CardNum = ?");
ps.setInt(1,pass);
ps.setString(2,CardNum);
ps.executeUpdate();
ps.close();
myP.removeAll();
JLabel pass1=new JLabel("密码修改成功");
pass1.setFont(new Font("宋体",Font.BOLD,24));
pass1.setForeground(Color.BLUE);
myP.add(pass1);
win1.setVisible(true);
}
//cs1.close();
cs.close();
con.close();
}
catch(SQLException e)
{
balance();
}
catch(ClassNotFoundException ex)
{
System.out.println("error");
}
}
class ActionListener1 implements ActionListener
{
int money3,password1;
Button btn7,btn8,ReturnBTN;
String x,y;
TextField tx5,tx6;
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==fileMenuItem1)
{
System.exit(0);
}
if(e.getSource()==helpMenuItem1)
{
dialog1.setSize(200,100);
dialog1.setVisible(true);
//dialog1.addWindowListener(new WindowListener2());
}
if(e.getSource()==ExitBTN)
{
if(flag==true)
{
myP.removeAll();
win1.dispose();
new JDBC();
}
}
if(e.getSource()==ClearBTN)
{
CardNumTxt.setText("");
PasswdTxt.setText("");
}
if(e.getSource()==LoginBTN)
{
CardNum=CardNumTxt.getText();
password=Integer.parseInt(PasswdTxt.getText());
login(CardNum,password);
}
if(e.getSource()==RemainBTN)
{
if(flag==true)
{
myP.removeAll();
balance();
}
}
if(e.getSource()==InfoviewBTN)
{
if(flag==true)
{
myP.removeAll();
Infoview();
}
}
if(e.getSource()==GetfeeBTN)
{
if(flag==true)
{
myP.removeAll();
JLabel money2=new JLabel("请输入金额:");
money2.setFont(new Font("宋体",Font.BOLD,14));
tx5=new TextField(10);
myP.add(money2);
myP.add(tx5);
btn7=new Button("OK");
btn7.addActionListener(new ActionListener2());
myP.add(btn7);
win1.setVisible(true);
//System.out.println(money3);
//Integer i2=new Integer(i2);
//int money3=i2.intValue();
//takeMoney(60);
}
}
if(e.getSource()==ChangePasswdBTN)
{
if(flag==true)
{
myP.removeAll();
JLabel pass3=new JLabel("请输入新密码:");
pass3.setFont(new Font("宋体",Font.BOLD,14));
tx6=new TextField(10);
tx6.setEchoChar('*');
myP.add(pass3);
myP.add(tx6);
btn8=new Button("OK");
btn8.addActionListener(new ActionListener2());
myP.add(btn8);
win1.setVisible(true);
}
}
}
class ActionListener2 implements ActionListener
{
public void actionPerformed(ActionEvent ee)
{
//System.out.println(money3);
if(ee.getSource()==btn7)
{
x=tx5.getText();
money3=Integer.parseInt(x);
takeMoney(money3);
}
if(ee.getSource()==btn8)
{
y=tx6.getText();
password1=Integer.parseInt(y);
updatePassword(password1);
}
}
}
}
class MyDialog extends Dialog
{
Label label1=new Label(" ATM简易测试版");
Label label2=new Label("作者:赵家伟 Version: 1.4");
MyDialog(Frame frame1,String title,boolean bool)
{
super(frame1,title,bool);
BorderLayout layout=new BorderLayout();
setLayout(layout);
add(label1,BorderLayout.NORTH);
add(label2,BorderLayout.SOUTH);
}
}
}
//-----------------------------------------------------------
class Logo extends JWindow implements Runnable
{
String filename;
public Logo(String name)
{
filename=name;
}
public Logo()
{
}
public void run()
{
URL imgURL = getClass().getResource(filename);
ImageIcon ig=new ImageIcon(imgURL);
JButton btn=new JButton(ig);
getContentPane().add(btn);
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension screenSize=kit.getScreenSize();
setLocation(screenSize.width/8,screenSize.height/8);
setSize(ig.getIconWidth(),ig.getIconHeight());
toFront();
thread1 thread2=new thread1();
thread2.start();
//setVisible(false);
}
public void setNotVisible()
{
setVisible(false);
}
class thread1 extends Thread
{
public void run()
{
try
{
setVisible(true);
sleep(4000);
setNotVisible();
}
catch(InterruptedException e)
{
System.out.print("error occours");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -