CSDN博客

img Inber

(java: jdbc:odbc 应用)客户偿还贷款

发表于2004/7/3 2:46:00  1375人阅读

(中文)要求:每当客户偿还某贷款金额时,他所取得的贷款材料与佘额必须在数据库中被更新。创建执行此任务应用。
(English)Require: When the client repay a certain lending money, the lending material and balance must be updte in database Who  get. please create the application of  task.

说明:Cregister存放的是客户信息Cloan存放的是其在银行的借款信息

注:本程序只对数据进行了更新,而没有按还贷规则做,阅读时请注意,程序大家可以完善一下。

注意此时表Cloan  loan_id为1的用户的贷款额

登录成功后输入还贷额。

0

 

                                   

注意表loan已经更新

注:本程序只对数据进行了更新,而没有按还贷规则做,阅读时请注意,程序大家可以完善一下。

/*******************************************************
 * 程序文件:   Saving.java
 * 建立时间:   2004年07月01日
 * 建立人:     InberKong
 * 最后修改:   2004年07月01日
 * 修改人:     InberKong
 * 功  能:    客户偿还贷款
 *******************************************************/
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.lang.*;

public class Saving extends JFrame implements ActionListener

{
 static JFrame frameObject;
 static JPanel panelObject;
 
 static JLabel labelRegid;
 static JLabel labelPsw;
 
 static JLabel labelReturncash;
 
 static JTextField textRegid;
 static JPasswordField textPsw;
 static JTextField textReturncash;
 
 static JButton buttonLogin;
 
 static JButton  buttonCheck;
 
 static ResultSet result;
 
 static Connection con;
 static  PreparedStatement stat; 
 static  String strSql;
 static String reg_id; 
 
 public Saving()
 {
  panelObject=new JPanel();
  frameObject.getContentPane().add(panelObject);
  frameObject.setDefaultCloseOperation(frameObject.EXIT_ON_CLOSE);
  
  labelRegid =new JLabel("labelRegid");
  labelPsw =new JLabel("labelPsw");
  labelReturncash=new JLabel("labelReturncash");
  
  textRegid=new JTextField(15);
  textPsw=new JPasswordField(15);
  
  textReturncash=new JTextField(15);
  
  buttonLogin= new JButton("登录");
  
  buttonCheck=new JButton("还款");
  
  panelObject.add(labelRegid);
  panelObject.add(textRegid);
  
  panelObject.add(labelPsw);
  panelObject.add(textPsw);

  panelObject.add(buttonLogin);  
  
  panelObject.add(labelReturncash);
  panelObject.add(textReturncash);
  
  panelObject.add(buttonCheck);
  

  this.labelReturncash.setVisible(false);
  this.textReturncash.setVisible(false);
  this.buttonCheck.setVisible(false);
  

  buttonLogin.addActionListener(this);
  buttonCheck.addActionListener(this); 
 }
 public static void main(String args[])
 {
  frameObject =new JFrame("贷款归还系统");
  frameObject.setDefaultCloseOperation(frameObject.EXIT_ON_CLOSE);
  frameObject.setVisible(true);
  
  frameObject.setSize(300,300);
  Saving h= new Saving();  
 }
  public void actionPerformed(ActionEvent evt)
  {
   Object obj=evt.getSource();
   if(obj==buttonLogin)
   {
    String CtextRegid=textRegid.getText();
    String CtextPsw=textPsw.getText();
    if(CtextRegid.length()==0)
      {
      JOptionPane.showMessageDialog(frameObject,new String("Please enter the Regid value!")); 
      }
    else if(CtextPsw.length()==0)
      {
     JOptionPane.showMessageDialog(frameObject,new String("Please enter the Psw value!")); 
      }
    else
       {
      try{ 
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
       Connection con;
       con=DriverManager.getConnection("jdbc:odbc:MyDataSource","sa","123");
       strSql="Select reg_id from Cregister where  reg_name=? and reg_psw=?";
       stat=con.prepareStatement(strSql);
       stat.setString(1,textRegid.getText());
       stat.setString(2,textPsw.getText());
       result=stat.executeQuery();
        if(result.next())
          {
         reg_id=result.getString(1);
          }
        if(reg_id=="" || reg_id==null)
        {
         JOptionPane.showMessageDialog(frameObject,new String("Login failed!!!!"));
        }
        else
        {JOptionPane.showMessageDialog(frameObject,new String("Login Successed!!!!"+reg_id)); 
        labelRegid.setVisible(false);
        labelPsw.setVisible(false);
        textRegid.setVisible(false);
        textPsw.setVisible(false);
        buttonLogin.setVisible(false);
        labelReturncash.setVisible(true);
        textReturncash.setVisible(true);
        buttonCheck.setVisible(true);           
        }
          
 
       }
       catch(Exception e)
       {
       System.out.println(" Could not execute the query "+e);
       }
      }
    }
    if(obj==buttonCheck)
    {
     
      try{ 
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
       Connection con;
       con=DriverManager.getConnection("jdbc:odbc:MyDataSource","sa","123");
       strSql="update  Cloan set loan_how=?  where loan_id=? ";
       stat=con.prepareStatement(strSql);
       stat.setString(1,textReturncash.getText());
       stat.setString(2,reg_id);
       stat.executeUpdate();
       JOptionPane.showMessageDialog(frameObject,new String("You cash have repay the bank! Operation Successed!"));
       }
       catch(Exception e)
       {
       System.out.println(" Could not execute the query "+e);
       }
    }
  }
}

阅读全文
0 0

相关文章推荐

img
取 消
img