⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dataaccess.java

📁 这个系统的功能是模拟ATM机的登陆、查询余额、取款、更改密码等功能
💻 JAVA
字号:
/*****************************************
 * <p>Title: ATM自动取款机</p>
 *
 * <p>Description: 模拟</p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author vinky_sc
 * @version 1.0
 *****************************************/
import java.sql.*;
import java.io.*;



public class dataAccess {
    private Connection con;
    private Statement stat;
    /*------------------------------------------
      -------------该方法用于连接数据库------------
      ------------------------------------------*/
    public dataAccess() //构造函数
    {
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String ur = "jdbc:odbc:Client";
            con = DriverManager.getConnection(ur);
            stat = con.createStatement();
        }
        catch(Exception e)
        {
              System.out.println(e.toString());
        }
    }
    /*----------------------------------------------
    --------该方法用于返回某一用户的数据信息------------
    -----------------------------------------------*/

    public ResultSet getData(String sql)//返回查询的数据信息
    {
            try
            {
                    ResultSet re = this.stat.executeQuery(sql);

                    /*String ID = re.getString(2);
                    String password = re.getString(3);
                    float balance = re.getInt(4);
                    System.out.println("ID"+ID);
                    System.out.println("password"+password);
                    System.out.println("balance"+balance);*/

                    return re;
            }
            catch(Exception e)
            {
                    System.out.println(e.toString());
                    return null;
            }
        }

        /*-------------------------------------
        -------选择数据信息的行数并返回-----------
        --------------------------------------*/

        public int getRow(String sql)
        {
                int i = 0;
                try
                {
                        ResultSet re = this.getData(sql);
                        while(re.next())
                        i++;
                }
                catch(Exception ex)
                {
                        System.out.println(ex.toString());
                }
                finally
                {
                        return i;
                }
        }
        /*-------------------------------------
        -------执行某一特定的无返回SQl语句--------
        --------------------------------------*/

        public boolean exeSql(String sql)//执行无返回的SQL语句
        {
                try
                {
                        stat.execute(sql);
                        return true;
                }
                catch(Exception ex)
                {
                        System.out.println(ex.toString());
                        return false;
                }
        }
        /*-------------------------------------
        -------------用于延时------------------
        --------------------------------------*/
        public void sleep(int second)
        {
                try
                {
                        Thread th = new Thread();
                        th.sleep(second*1000);
                }
                catch(Exception e)
                {
                        System.out.println(e.toString());
                }
        }
        protected void finalize()//析构函数
        {
                try
                {
                        if(stat != null)
                                stat.close();
                        if(con != null)
                                con.close();
                }
        catch(Exception e)
        {}
        }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -