亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? remotedbbankserver.java

?? Examples From Java Examples in a Nutshell, 2nd Edition 書中的源碼
?? JAVA
字號:
/* * Copyright (c) 2000 David Flanagan.  All rights reserved. * This code is from the book Java Examples in a Nutshell, 2nd Edition. * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied. * You may study, use, and modify it for any non-commercial purpose. * You may distribute it non-commercially as long as you retain this notice. * For a commercial use license, or to purchase the book (recommended), * visit http://www.davidflanagan.com/javaexamples2. */package com.davidflanagan.examples.sql;import java.rmi.*;import java.rmi.server.*;import java.rmi.registry.*;import java.sql.*;import java.io.*;import java.util.*;import java.util.Date; // import explicitly to disambiguate from java.sql.Dateimport com.davidflanagan.examples.rmi.Bank.*;  // Import inner classes of Bank/** * This class is another implementation of the RemoteBank interface. * It uses a database connection as its back end, so that client data isn't * lost if the server goes down.  Note that it takes the database connection * out of "auto commit" mode and explicitly calls commit() and rollback() to * ensure that updates happen atomically. **/public class RemoteDBBankServer extends UnicastRemoteObject    implements RemoteBank{    Connection db;   // The connection to the database that stores account info        /** The constructor.  Just save the database connection object away */    public RemoteDBBankServer(Connection db) throws RemoteException {         this.db = db;    }        /** Open an account */    public synchronized void openAccount(String name, String password)	throws RemoteException, BankingException    {        // First, check if there is already an account with that name        Statement s = null;        try {             s = db.createStatement();            s.executeQuery("SELECT * FROM accounts WHERE name='" + name + "'");            ResultSet r = s.getResultSet();            if (r.next()) throw new BankingException("Account name in use.");	                // If it doesn't exist, go ahead and create it Also, create a            // table for the transaction history of this account and insert an            // initial transaction into it.            s = db.createStatement();            s.executeUpdate("INSERT INTO accounts VALUES ('" + name + "', '" +			    password + "', 0)");            s.executeUpdate("CREATE TABLE " + name + 			    "_history (msg VARCHAR(80))");            s.executeUpdate("INSERT INTO " + name + "_history " +			    "VALUES ('Account opened at " + new Date() + "')");	                // And if we've been successful so far, commit these updates,            // ending the atomic transaction.  All the methods below also use            // this atomic transaction commit/rollback scheme            db.commit();        }        catch(SQLException e) {            // If an exception was thrown, "rollback" the prior updates,            // removing them from the database.  This also ends the atomic            // transaction.            try { db.rollback(); } catch (Exception e2) {}            // Pass the SQLException on in the body of a BankingException            throw new BankingException("SQLException: " + e.getMessage() + 				       ": " + e.getSQLState());        }        // No matter what happens, don't forget to close the DB Statement        finally { try { s.close(); } catch (Exception e) {} }    }        /**      * This convenience method checks whether the name and password match     * an existing account.  If so, it returns the balance in that account.     * If not, it throws an exception.  Note that this method does not call     * commit() or rollback(), so its query is part of a larger transaction.     **/    public int verify(String name, String password) 	throws BankingException, SQLException    {        Statement s = null;        try {            s = db.createStatement();            s.executeQuery("SELECT balance FROM accounts " +			   "WHERE name='" + name + "' " +			   "  AND password = '" + password + "'");            ResultSet r = s.getResultSet();            if (!r.next())                throw new BankingException("Bad account name or password");            return r.getInt(1);        }        finally { try { s.close(); } catch (Exception e) {} }    }        /** Close a named account */    public synchronized FunnyMoney closeAccount(String name, String password)	throws RemoteException, BankingException    {        int balance = 0;        Statement s = null;        try {            balance = verify(name, password);            s = db.createStatement();            // Delete the account from the accounts table            s.executeUpdate("DELETE FROM accounts " + 			    "WHERE name = '" + name + "' " +			    "  AND password = '" + password + "'");            // And drop the transaction history table for this account            s.executeUpdate("DROP TABLE " + name + "_history");            db.commit();        }        catch (SQLException e) {            try { db.rollback(); } catch (Exception e2) {}            throw new BankingException("SQLException: " + e.getMessage() + 				       ": " + e.getSQLState());        }        finally { try { s.close(); } catch (Exception e) {} }	        // Finally, return whatever balance remained in the account        return new FunnyMoney(balance);    }        /** Deposit the specified money into the named account */    public synchronized void deposit(String name, String password, 				     FunnyMoney money) 	throws RemoteException, BankingException    {        int balance = 0;         Statement s = null;        try {            balance = verify(name, password);            s = db.createStatement();            // Update the balance            s.executeUpdate("UPDATE accounts " +			    "SET balance = " + balance + money.amount + " " +			    "WHERE name='" + name + "' " +			    "  AND password = '" + password + "'");            // Add a row to the transaction history            s.executeUpdate("INSERT INTO " + name + "_history " + 			    "VALUES ('Deposited " + money.amount + 			    " at " + new Date() + "')");            db.commit();        }        catch (SQLException e) {            try { db.rollback(); } catch (Exception e2) {}            throw new BankingException("SQLException: " + e.getMessage() + 				       ": " + e.getSQLState());        }        finally { try { s.close(); } catch (Exception e) {} }    }        /** Withdraw the specified amount from the named account */    public synchronized FunnyMoney withdraw(String name, String password, 					    int amount)	throws RemoteException, BankingException    {        int balance = 0;        Statement s = null;        try {            balance = verify(name, password);            if (balance < amount)		throw new BankingException("Insufficient Funds");            s = db.createStatement();            // Update the account balance            s.executeUpdate("UPDATE accounts " +			    "SET balance = " + (balance - amount) + " " +			    "WHERE name='" + name + "' " +			    "  AND password = '" + password + "'");            // Add a row to the transaction history            s.executeUpdate("INSERT INTO " + name + "_history " + 			    "VALUES ('Withdrew " + amount + 			    " at " + new Date() + "')");            db.commit();        }        catch (SQLException e) {            try { db.rollback(); } catch (Exception e2) {}            throw new BankingException("SQLException: " + e.getMessage() + 				       ": " + e.getSQLState());        }        finally { try { s.close(); } catch (Exception e) {} }	        return new FunnyMoney(amount);    }        /** Return the balance of the specified account */    public synchronized int getBalance(String name, String password)	throws RemoteException, BankingException    {        int balance;        try {            // Get the balance            balance = verify(name, password);            // Commit the transaction            db.commit();        }        catch (SQLException e) {            try { db.rollback(); } catch (Exception e2) {}            throw new BankingException("SQLException: " + e.getMessage() + 				       ": " + e.getSQLState());        }        // Return the balance        return balance;    }        /** Get the transaction history of the named account */    public synchronized List getTransactionHistory(String name, 						   String password)	throws RemoteException, BankingException    {        Statement s = null;        List list = new ArrayList();        try {            // Call verify to check the password, even though we don't             // care what the current balance is.            verify(name, password);            s = db.createStatement();            // Request everything out of the history table            s.executeQuery("SELECT * from " + name + "_history");            // Get the results of the query and put them in a Vector            ResultSet r = s.getResultSet();            while(r.next()) list.add(r.getString(1));            // Commit the transaction            db.commit();        }        catch (SQLException e) {            try { db.rollback(); } catch (Exception e2) {}            throw new BankingException("SQLException: " + e.getMessage() + 				       ": " + e.getSQLState());        }        finally { try { s.close(); } catch (Exception e) {} }        // Return the Vector of transaction history.        return list;    }        /**     * This main() method is the standalone program that figures out what     * database to connect to with what driver, connects to the database,     * creates a RemoteDBBankServer object, and registers it with the registry,     * making it available for client use     **/    public static void main(String[] args) {        try {            // Create a new Properties object.  Attempt to initialize it from            // the BankDB.props file or the file optionally specified on the             // command line, ignoring errors.            Properties p = new Properties();            try { p.load(new FileInputStream(args[0])); }            catch (Exception e) {                try { p.load(new FileInputStream("BankDB.props")); }                catch (Exception e2) {}            }	                // The BankDB.props file (or file specified on the command line)            // must contain properties "driver" and "database", and may            // optionally contain properties "user" and "password".            String driver = p.getProperty("driver");            String database = p.getProperty("database");            String user = p.getProperty("user", "");            String password = p.getProperty("password", "");	                // Load the database driver class            Class.forName(driver);	                // Connect to the database that stores our accounts            Connection db = DriverManager.getConnection(database,							user, password);	                // Configure the database to allow multiple queries and updates            // to be grouped into atomic transactions            db.setAutoCommit(false);            db.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);	                // Create a server object that uses our database connection            RemoteDBBankServer bank = new RemoteDBBankServer(db);	                // Read a system property to figure out how to name this server.            // Use "SecondRemote" as the default.            String name = System.getProperty("bankname", "SecondRemote");	                // Register the server with the name            Naming.rebind(name, bank);	                // And tell everyone that we're up and running.            System.out.println(name + " is open and ready for customers.");        }        catch (Exception e) {            System.err.println(e);            if (e instanceof SQLException)                 System.err.println("SQL State: " +				   ((SQLException)e).getSQLState());            System.err.println("Usage: java [-Dbankname=<name>] " +		        "com.davidflanagan.examples.sql.RemoteDBBankServer " +			       "[<dbpropsfile>]");            System.exit(1);        }    }}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品电影一区二区| 日韩成人精品在线观看| 国产精品婷婷午夜在线观看| 亚洲国产精品国自产拍av| 亚洲欧美日韩在线| 久久国产婷婷国产香蕉| 成人午夜激情在线| 欧美美女一区二区在线观看| 久久久久久久精| 亚洲国产精品久久人人爱| 久久精品国产亚洲高清剧情介绍| 欧美不卡视频一区| 偷拍自拍另类欧美| 色综合色狠狠天天综合色| 久久久高清一区二区三区| 成人小视频在线| 午夜欧美在线一二页| 久久影院午夜论| 九九视频精品免费| 日韩亚洲欧美成人一区| 亚洲成人激情综合网| 在线观看免费一区| 国产精品久久久久久妇女6080| 九九精品一区二区| 亚洲视频在线一区二区| 不卡av在线免费观看| 久久久久久久久99精品| 欧美系列日韩一区| 亚洲午夜精品网| 久久久亚洲精品石原莉奈| 91搞黄在线观看| 丝袜亚洲精品中文字幕一区| 欧美日韩综合色| 五月天激情小说综合| 日本一区二区视频在线| 99re这里只有精品首页| 国产精品二三区| 日韩视频在线一区二区| 色88888久久久久久影院野外| 九九久久精品视频| 亚洲大尺度视频在线观看| 国产欧美一区二区三区网站| 91精品国产手机| 美女视频网站黄色亚洲| 日韩欧美国产综合| 麻豆传媒一区二区三区| 一级日本不卡的影视| 91九色最新地址| 国产**成人网毛片九色 | 五月综合激情婷婷六月色窝| 国产欧美一区二区三区在线看蜜臀| 国产精品一二三在| 91麻豆精品国产91久久久久久| 日韩电影在线观看电影| 樱桃国产成人精品视频| 欧美日韩一区小说| proumb性欧美在线观看| 国产精品高潮久久久久无| 欧美一级一区二区| 欧美日韩欧美一区二区| 色香蕉久久蜜桃| 91麻豆精品秘密| 91网站在线观看视频| 韩国成人在线视频| 中文字幕一区二区三| 在线成人午夜影院| 欧美三级中文字幕| 欧美在线观看你懂的| 在线观看一区二区精品视频| 97久久精品人人做人人爽| 成人黄色777网| 成人激情校园春色| 成人动漫一区二区在线| 波多野结衣中文字幕一区 | 日韩精品高清不卡| 亚洲成人免费影院| 全部av―极品视觉盛宴亚洲| 国产欧美精品一区| 国产日韩精品视频一区| 欧美国产精品久久| 中文字幕av一区 二区| 国产精品免费观看视频| 国产精品激情偷乱一区二区∴| 国产精品国产三级国产aⅴ中文| 国产清纯在线一区二区www| 国产精品看片你懂得| 亚洲欧美日韩国产手机在线| 又紧又大又爽精品一区二区| 亚洲影视在线播放| 国产精品第四页| 亚洲免费观看高清完整版在线观看熊 | 成人黄色小视频| 91免费看视频| 欧美日韩亚洲国产综合| 欧美高清视频在线高清观看mv色露露十八| 欧美日韩激情在线| 一本到不卡精品视频在线观看| 在线免费一区三区| 欧美精品日韩一区| 久久综合九色综合久久久精品综合| 国产丝袜美腿一区二区三区| 精品区一区二区| 中文字幕+乱码+中文字幕一区| 亚洲激情五月婷婷| 免费成人性网站| 成人一区二区视频| 欧洲精品一区二区三区在线观看| 欧美一区二区黄色| 综合在线观看色| 日韩精品亚洲专区| 成人蜜臀av电影| 欧美日韩1234| 国产精品人妖ts系列视频| 亚洲综合区在线| 国产精品99久久久久久似苏梦涵| 91麻豆福利精品推荐| 日韩精品一区二区三区中文精品| 国产精品欧美一区喷水| 日韩精品一二区| 99麻豆久久久国产精品免费优播| 7777精品伊人久久久大香线蕉的| 国产精品色哟哟| 久草精品在线观看| 欧亚洲嫩模精品一区三区| 国产日韩三级在线| 五月婷婷激情综合| 91美女片黄在线| xf在线a精品一区二区视频网站| 亚洲自拍偷拍欧美| 成人一道本在线| 欧美电影精品一区二区| 亚洲精品国产无天堂网2021| 国产精品123区| 99国产欧美另类久久久精品| 欧美大尺度电影在线| 亚洲综合一二三区| 91视频你懂的| 日本一区二区综合亚洲| 精品一区二区三区香蕉蜜桃 | 国产精品美女久久久久久久网站| 日韩精品午夜视频| 精品视频一区三区九区| 国产精品免费视频网站| 国产乱码精品一区二区三区忘忧草 | 亚洲成a人片在线不卡一二三区| kk眼镜猥琐国模调教系列一区二区| 亚洲精品在线免费观看视频| 婷婷成人激情在线网| 色中色一区二区| 亚洲色图视频网| 成人激情黄色小说| 欧美国产综合一区二区| 国产福利一区二区三区视频| 欧美成人精品高清在线播放| 三级久久三级久久久| 欧美色倩网站大全免费| 亚洲图片欧美综合| 欧美性感一区二区三区| 一区二区在线看| 欧美在线观看视频一区二区| 一区二区在线观看免费视频播放| 91丨九色丨蝌蚪丨老版| 1000精品久久久久久久久| 不卡av免费在线观看| 亚洲色图.com| 一本到三区不卡视频| 亚洲综合在线电影| 91国内精品野花午夜精品 | 欧美mv日韩mv国产网站app| 日本美女一区二区三区视频| 91精品久久久久久久久99蜜臂| 日日夜夜精品视频免费| 欧美老人xxxx18| 美女免费视频一区二区| 亚洲精品一区二区三区影院 | 麻豆成人在线观看| 2023国产精品| 成人综合在线观看| 亚洲欧洲综合另类在线 | 欧美一区二区黄| 国产一区二区按摩在线观看| 欧美三级三级三级爽爽爽| 日韩国产欧美在线观看| 日韩精品一区二区在线观看| 国产精品66部| 亚洲女厕所小便bbb| 91精选在线观看| 国产一区二区三区免费在线观看 | 亚洲人成在线观看一区二区| 91精品91久久久中77777| 亚洲gay无套男同| 精品国产污污免费网站入口 | 中文字幕乱码日本亚洲一区二区| 91在线高清观看| 日本 国产 欧美色综合| 国产精品网友自拍| 91精品国产综合久久精品图片| 国产一区二区在线观看视频| 亚洲精品高清在线观看| 日韩三级中文字幕|