dbtest.java

来自「挺好的JAVA例子,可用MYSQL,ACCESS,ORACLE做后台,例子中包括」· Java 代码 · 共 67 行

JAVA
67
字号

public class DBTest {

	public static void main(String[] args) {
		try {
			ClientBillingDB db = new ClientBillingDB();

			//Test transaction insertion, updating, deletion
			Transaction t = new Transaction();
			t.amount = 5;
			t.clientID = 2;
			t.date = "04-03-1981";
			t.description = "new transaction";
			t.transactionID = 24;
			
			db.create(t);
			
			//Update ID
			t.transactionID = 112; 
			db.update(24, t);

			//Update a different non-key field			
			t.description = "updated description"; 
			db.update(t.transactionID, t);

			db.delete(t);

			
			Client c = new Client();
			c.address = "333 Strad";
			c.clientID = 100;
			c.dob = "1981-02-04";
			c.email = "walt@straf.com";
			c.firstName = "Walter";
			c.lastName = "Kronk";
			c.miscInfo = "He enjoys long walks.";
			c.phone = "120-4355";
			
			db.create(c);
			
			c.clientID = 99;
			db.update(100, c);

			c.firstName = "Albert";
			db.update(c.clientID, c);
			
			db.delete(c);


			//Display results
			//Get clients
			Client[] clients = db.retrieveClients();
			for (int i = 0; i < clients.length; i++)
				System.out.println(clients[i]);

			//Get transactions
			Transaction[] trans = db.retrieveTransactions(clients[0].clientID);
			for (int i = 0; i < trans.length; i++)
				System.out.println(trans[i]);

			db.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

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