Recently The Java Remote Method Invocation (RMI) system allows an object running in one Java virtual machine to invoke methods on an object running in another Java virtual machine. RMI provides for remote communication between programs written in the Java programming language.
The presentation given at MSBTE sponsored content updating program on 'Advanced Java Programming' for Diploma Engineering teachers of Maharashtra. Venue: Guru Gobind Singh Polytechnic, Nashik
Date: 22/12/2010
Session: Java Network Programming
Hai I'm Senthilkanth, doing MCA in Mepco Schlenk Engineering College..
The following presentation covers topic called WML for BSc CS, BCA, MSc CS, MCA, ME students.Make use of it. WML Script by Shanti katta.
This presentation agenda like,
Recently The Java Remote Method Invocation (RMI) system allows an object running in one Java virtual machine to invoke methods on an object running in another Java virtual machine. RMI provides for remote communication between programs written in the Java programming language.
The presentation given at MSBTE sponsored content updating program on 'Advanced Java Programming' for Diploma Engineering teachers of Maharashtra. Venue: Guru Gobind Singh Polytechnic, Nashik
Date: 22/12/2010
Session: Java Network Programming
Hai I'm Senthilkanth, doing MCA in Mepco Schlenk Engineering College..
The following presentation covers topic called WML for BSc CS, BCA, MSc CS, MCA, ME students.Make use of it. WML Script by Shanti katta.
This presentation agenda like,
It is an IETF standardization initiative whose goal is to come out with an Internet standard Version of SSL. The presentation discusses all. Happy Learning. :)
A distributed system is a collection of computational and storage devices connected through a communications network. In this type of system, data, software, and users are distributed.
User Interfaces can be modeled in a technology agnostic way using Conceptual User Interface Patterns. This talk shows how to take advantage of this approach and shows how to generate code to different devices and technologies.
Layer between OS and distributed applications,Hides complexity and heterogeneity of distributed system ,Bridges gap between low-level OS communications and programming language abstractions,Provides common programming abstraction and infrastructure for distributed applications.
Remote Procedure Call in Distributed SystemPoojaBele1
Presentation to give description about the remote procedure call in distributed systems
Presentation covers some points on remote procedure call in distributed systems
Remote Method Invocation, Distributed Programming in java, Java Distributed Programming, Network Programming in JAVA, Core Java, Introduction to RMI, Getting Started with RMI, Getting Started with Remote Method Invocation, Distributed Programming, Java, J2SE
In a world where users have ever higher expectations from the apps they use, having data always available, even when the device is offline, has become increasingly important.
In this talk you will learn how thinking "offline first" not only makes your app architecture better but also result in cleaner code and happier users.
I will introduce Realm, a new database for easy persistence, and demonstrate how it enables truly reactive UI's by fitting seamlessly into the standard network stack of Retrofit and RxJava.
Finally we will take a look at the new Realm Mobile Platform, which provides real-time synchronization between devices, enabling features previously out of reach for many development teams.
It is an IETF standardization initiative whose goal is to come out with an Internet standard Version of SSL. The presentation discusses all. Happy Learning. :)
A distributed system is a collection of computational and storage devices connected through a communications network. In this type of system, data, software, and users are distributed.
User Interfaces can be modeled in a technology agnostic way using Conceptual User Interface Patterns. This talk shows how to take advantage of this approach and shows how to generate code to different devices and technologies.
Layer between OS and distributed applications,Hides complexity and heterogeneity of distributed system ,Bridges gap between low-level OS communications and programming language abstractions,Provides common programming abstraction and infrastructure for distributed applications.
Remote Procedure Call in Distributed SystemPoojaBele1
Presentation to give description about the remote procedure call in distributed systems
Presentation covers some points on remote procedure call in distributed systems
Remote Method Invocation, Distributed Programming in java, Java Distributed Programming, Network Programming in JAVA, Core Java, Introduction to RMI, Getting Started with RMI, Getting Started with Remote Method Invocation, Distributed Programming, Java, J2SE
In a world where users have ever higher expectations from the apps they use, having data always available, even when the device is offline, has become increasingly important.
In this talk you will learn how thinking "offline first" not only makes your app architecture better but also result in cleaner code and happier users.
I will introduce Realm, a new database for easy persistence, and demonstrate how it enables truly reactive UI's by fitting seamlessly into the standard network stack of Retrofit and RxJava.
Finally we will take a look at the new Realm Mobile Platform, which provides real-time synchronization between devices, enabling features previously out of reach for many development teams.
Frequency .java Word frequency counter package frequ.pdfarshiartpalace
Frequency .java
/**
* Word frequency counter
*/
package frequency;
import java.util.Iterator;
/**
*
* @author UMD CS
*/
public class Frequency implements Iterable{
private Node first;
private int N;
Frequency(){
N = 0;
first = null;
}
@Override
public Iterator iterator() {
return new ListIterator();
}
/**
*
* List iterator
*
*/
private class ListIterator implements Iterator{
private Node current;
private int index ;
ListIterator(){
current = first;
index = 0;
}
@Override
public boolean hasNext() {
return current != null;
}
public String next() {
if(!hasNext()){
return null;
}
String word = current.key;
int count = current.count;
String r = \"(\"+word + \",\" + Integer.toString(count)+\")\";
current = current.next;
return r;
}
@Override
public void remove() {
}
}
/**
*
* Node class
*
*/
private class Node {
private String key;
private int count;
private Node next;
Node(String item){
key = item;
count = 1;
next = null;
}
@Override
public String toString(){
return \"(\"+key +\",\"+count+\")\";
}
}
/*
* Inserts a word into the linked list. If the word exists, increment the
* count by q.
*/
public void insert(String word){
if(word.equals(\"\")){
return;
}
//TODO
/*
* implement here
*/
}
/**
*
* @param str input string
* This method splits a string into words and pass the words to insert method
*
*/
public void insertWords(String str){
String delims = \"[ .,?!\'\\\"()}{;/<>&=#-:\\\\ _]+\";
String[] words = str.split(delims);
for(String s: words){
s = s.toLowerCase();
insert(s);
}
}
/**
* prints the word frequency list
*/
public void print(){
Node c = first;
while(c != null){
System.out.print(\"(\"+c.key + \",\" + c.count+\")\");
c = c.next;
}
System.out.print(\"\ \");
}
}
--------------------------------------------------------------------------------------------------------------------
------------------------------------------------------
WordFrequency.java
package frequency;
import utils.In;
import utils.Stopwatch;
/**
*
* @author UMD CS
*/
public class WordFrequency {
/**
* @param input source
* @param
* This method receives input resource and return the word frequency string
* DO NOT CHANGE THIS METHOD.
*/
public static String freq(String inputSource, int maxLines){
In in;
// Frequency class can only count the frequency of strings. DO NOT CHANGE THIS.
Frequency freq = new Frequency();
int MAX = 100;
String inputSourceName = inputSource;
try {
in = new In(inputSourceName);
while (!in.isEmpty()) {
String s = in.readLine();
//System.out.println(s);
freq.insertWords(s);
}
}
catch (Exception e) {
e.printStackTrace();
}
StringBuilder strFrequency = new StringBuilder();
int cnt = 0;
for(String s: freq){
strFrequency.append(s);
strFrequency.append(\",\");
cnt++;
if(cnt >= maxLines){break;}
}
return strFrequency.toString();
}
/**
*
*/
public static void main(String[] args) {
In in;
Frequency freq = new Frequency();
int MAX = 100;
// String inputSourceName =
\"http://www.cs.umd.edu/class/summer2015/cmsc132/projects/P3_WordFrequency/test1.html\";
String .
When embracing Java 8 we walk down the yellow brick road to the wizard of lambdas. That road usually starts from the fear and terror of learning their syntax until finally getting to understand them and opening our minds to the fruitful fields of functional programming. But this road eventually reaches a final stage: the lambda abuse.
To master the lambdas art means to know when to use them and when not to not damage your brain and, most importantly, other Java developers’. Keep your code readable and maintainable, avoid becoming a lambda addict!
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
Ethnobotany and Ethnopharmacology:
Ethnobotany in herbal drug evaluation,
Impact of Ethnobotany in traditional medicine,
New development in herbals,
Bio-prospecting tools for drug discovery,
Role of Ethnopharmacology in drug evaluation,
Reverse Pharmacology.
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
What is the purpose of the Sabbath Law in the Torah. It is interesting to compare how the context of the law shifts from Exodus to Deuteronomy. Who gets to rest, and why?
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
How to Split Bills in the Odoo 17 POS ModuleCeline George
Bills have a main role in point of sale procedure. It will help to track sales, handling payments and giving receipts to customers. Bill splitting also has an important role in POS. For example, If some friends come together for dinner and if they want to divide the bill then it is possible by POS bill splitting. This slide will show how to split bills in odoo 17 POS.
1. Assosa University
College of Computing and Informatics
Department of Computer Science
Int. to Distriburted Systems
Remote Method Invocation Lab. Manual
B.Sc. in Computer Science
Prepared by Gebreigziabher A. (M.Sc)
May, 2018
2. Assosa University College of Computing and Informatics
Department of Computer Science Distributed Systems Lab Manuallllllllllllll2
RMI Programming Lab. Manual
RMI Programming Lab 1 – Basics - Hello World!
1. RMI Interface
//RMIInterface.java
public interface RMIInterface extends Remote {
public String displayMessage() throws RemoteException;
}
2. RMI Server
//RMIServer.java
public class RMIServer extends UnicastRemoteObject implements RMIInterface {
public RMIServer() throws RemoteException {
//Default Constructor
}
public String displayMessage() throws RemoteException {
return "Hello World! This is Response from Server!";
}
public static void main(String[] args) {
try {
Registry r = LocateRegistry.createRegistry(3232);
RMIServer s = new RMIServer();
r.rebind("x", s);
System.out.println("The Server is Running!");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
3. Assosa University College of Computing and Informatics
Department of Computer Science Distributed Systems Lab Manuallllllllllllll3
3. RMI Client
//RMIClient.java
public class RMIClient {
public static void main(String[] args) {
// TODO code application logic here
try {
RMIInterface ri = (RMIInterface) Naming.lookup("rmi://localhost:3232/x");
String res = ri.displayMessage(); //Method Invocation
System.out.println(res);
}catch(Exception ex){
ex.printStackTrace();
}
}
}
RMI Programming Lab 2 – Basics - Mathematical Operations
1. RMI Interface
//RMIInterface.java
public interface RMIInterface extends Remote {
public double add(double a, double b) throws RemoteException;
public double subtract(double a, double b) throws RemoteException;
public double computeSquareRoot(double a) throws RemoteException;
public double raise(double a, double b) throws RemoteException;
}
2. RMI Server
//RMIServer.java
public class RMIServer extends UnicastRemoteObject implements RMIInterface {
public RMIServer() throws RemoteException {
//Default Constructor
}
public double add(double a, double b) throws RemoteException {
return a + b;
}
4. Assosa University College of Computing and Informatics
Department of Computer Science Distributed Systems Lab Manuallllllllllllll4
public double subtract(double a, double b) throws RemoteException {
return a - b;
}
public double computeSquareRoot(double a) throws RemoteException{
return Math.sqrt(a);
}
public double raise(double a, double b) throws RemoteException{
return Math.pow(a,b);
}
public static void main(String[] args) {
try {
Registry r = LocateRegistry.createRegistry(3232);
RMIServer s = new RMIServer();
r.rebind("x", s);
System.out.println("Server is Ready!");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
3. RMI Client
//RMIClient.java
public class RMIClient {
public static void main(String[] args) {
// TODO code application logic here
try {
double a = 9, b = 3;
RMIInterface ri = (RMIInterface) Naming.lookup("rmi://localhost:3232/x");
double sum = ri.add(a, b);
System.out.println("The Sum = " + sum);
double diff = ri.subtract(a, b);
System.out.println("The Diff =" + diff);
double sq = ri.computeSquareRoot(a);
System.out.println("The SQRT =" + sq);
double p = ri.raise(a, b);
System.out.println("Power = " + p);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
5. Assosa University College of Computing and Informatics
Department of Computer Science Distributed Systems Lab Manuallllllllllllll5
RMI Lab Programming – JDBC
RMI Programming Lab 3 – JDBC – Database Design
CREATE DATABASE phonedir;
USE phonedir;
CREATE TABLE IF NOT EXISTS contact (
contactname varchar(20) NOT NULL,
phoneno varchar(20) NOT NULL,
PRIMARY KEY (phoneno)
);
6. Assosa University College of Computing and Informatics
Department of Computer Science Distributed Systems Lab Manuallllllllllllll6
RMI Programming Lab 3 – JDBC – INSERT OPERATION
1. RMI Interface
//RMIInterface.java
public interface RMIInterface extends Remote {
public String addContact(String contactName, String phoneNo) throws RemoteException;
}
2. RMI Server
//RMIServer.java
public class RMIServer extends UnicastRemoteObject implements RMIInterface {
static final String DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/phonedir";
Connection conn = null;
Statement stmt = null;
ResultSet rs;
public RMIServer() throws RemoteException {
}
public String addContact(String contactName, String phoneNo) throws RemoteException {
String phoneNumber = "", val = "";
try {
Class.forName(DRIVER);
conn = DriverManager.getConnection(DB_URL, "root", "");
stmt = conn.createStatement();
String sql = "SELECT * FROM contact WHERE phoneno = '" + phoneNo + "'";
rs = stmt.executeQuery(sql);
while (rs.next()) {
phoneNumber = rs.getString("phoneno");
}
if (phoneNo.intern().equals(phoneNumber)) {
val = "0"; //Duplicate
} else if (!phoneNo.intern().equals(phoneNumber)) {
stmt = conn.createStatement();
String sql1 = "INSERT INTO contact(contactname, phoneno) VALUES('" +
contactName + "','" + phoneNo + "')";
stmt.executeUpdate(sql1);
val = "1"; //Successfully Registered
}
} catch (Exception ex) {
ex.printStackTrace();
7. Assosa University College of Computing and Informatics
Department of Computer Science Distributed Systems Lab Manuallllllllllllll7
}
return val;
}
public static void main(String[] args) {
try {
Registry r = LocateRegistry.createRegistry(1010);
RMIServer rs = new RMIServer();
r.rebind("x", rs);
System.out.println("Server Ready!");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
3. RMI Client
//RMIClient.java: Inside btnRegisterActionPerformed
try {
String contactName = txtName.getText();
String phoneNo = txtPhoneNo.getText();
RMIInterface ri = (RMIInterface) Naming.lookup("rmi://localhost:1010/x");
String res = ri.addContact(contactName, phoneNo);
if (res.equals("1")) {
JOptionPane.showMessageDialog(this, "Contact has been Registered!", "Phone
Dir: Contact Registered.", JOptionPane.INFORMATION_MESSAGE);
} else if (res.equals("0")) {
JOptionPane.showMessageDialog(this, "Contact already Exist!", "Phone Dir:
Contact Exist.", JOptionPane.INFORMATION_MESSAGE);
}
} catch (Exception ex) {
ex.printStackTrace();
}
8. Assosa University College of Computing and Informatics
Department of Computer Science Distributed Systems Lab Manuallllllllllllll8
RMI Programming Lab 4 – JDBC – SELECT OPERATION
1. RMI Interface
//RMIInterface.java
public interface RMIInterface extends Remote {
public ArrayList searchContact(String phoneNo) throws RemoteException;
}
2. RMI Server
//RMIServer.java
public class RMIServer extends UnicastRemoteObject implements RMIInterface {
static final String DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/phonedir";
Connection conn = null;
Statement stmt = null;
ResultSet rs;
public RMIServer() throws RemoteException {
}
public ArrayList searchContact(String phoneNo) throws RemoteException {
ArrayList array = new ArrayList();
try {
Class.forName(DRIVER);
conn = DriverManager.getConnection(DB_URL, "root", "");
stmt = conn.createStatement();
String sql = "SELECT *FROM contact WHERE phoneno ='" + phoneNo + "'";
rs = stmt.executeQuery(sql);
while (rs.next()) {
for (int i = 0; i < 2; i++) {
array.add(rs.getString(i + 1));
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
return array;
}
9. Assosa University College of Computing and Informatics
Department of Computer Science Distributed Systems Lab Manuallllllllllllll9
public static void main(String[] args) {
try {
Registry r = LocateRegistry.createRegistry(1010);
RMIServer rs = new RMIServer();
r.rebind("x", rs);
System.out.println("Server Ready!");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
3. RMI Client
//RMIClient.java: Inside btnSearchActionPerformed
ArrayList array = new ArrayList();
try {
String phoneNo = txtSearchPhone.getText();
RMIInterface ri = (RMIInterface) Naming.lookup("rmi://localhost:1010/x");
for (int i = 0; i < 2; i++) {
array = ri.searchContact(phoneNo);
}
if (!array.isEmpty()) {
txtName.setText(array.get(0).toString());
txtPhoneNo.setText(array.get(1).toString());
} else if (array.isEmpty()) {
JOptionPane.showMessageDialog(this, "No record found.", "Phone Dire: No
Record Found", JOptionPane.INFORMATION_MESSAGE);
}
} catch (Exception ex) {
ex.printStackTrace();
}
RMI Programming Lab 5 – JDBC – SELECT OPERATION
1. RMI Interface
//RMIInterface.java
public interface RMIInterface extends Remote {
public ArrayList viewAllContacts(int i) throws RemoteException;
}
2. RMI Server
//RMIServer.java
public class RMIServer extends UnicastRemoteObject implements RMIInterface {
static final String DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/phonedir";
10. Assosa University College of Computing and Informatics
Department of Computer Science Distributed Systems Lab Manuallllllllllllll10
Connection conn = null;
Statement stmt = null;
ResultSet rs;
public RMIServer() throws RemoteException {
}
public ArrayList viewAllContacts(int i) throws RemoteException {
ArrayList array = new ArrayList();
try {
Class.forName(DRIVER);
conn = DriverManager.getConnection(DB_URL, "root", "");
stmt = conn.createStatement();
String sql = "SELECT contactname, phoneno FROM contact ORDER BY contactname DESC";
stmt.execute(sql);
rs = stmt.getResultSet();
while (rs.next()) {
array.add(rs.getObject(i + 1));
}
} catch (Exception ex) {
ex.printStackTrace();
}
return array;
}
public static void main(String[] args) {
try {
Registry r = LocateRegistry.createRegistry(1010);
RMIServer rs = new RMIServer();
r.rebind("x", rs);
System.out.println("Server Ready!");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
3. RMI Client
//RMIClient.java: Inside btnViewAllActionPerformed
DefaultTableModel model = (DefaultTableModel) tblContacts.getModel();
ArrayList array = new ArrayList();
try {
RMIInterface ri = (RMIInterface) Naming.lookup("rmi://localhost:1010/x");
int total = 0;
for (int i = 0; i < 2; i++) {
11. Assosa University College of Computing and Informatics
Department of Computer Science Distributed Systems Lab Manuallllllllllllll11
array = ri.viewAllContacts(i);
for (int j = 0; j < array.size(); j++) {
model.setValueAt(array.get(j), j, i);
}
total = array.size();
}
if (total == 0) {
JOptionPane.showMessageDialog(this, "No Contact Found!", "Tele Directory: No
Contact Exist.", JOptionPane.INFORMATION_MESSAGE);
}
} catch (Exception ex) {
ex.printStackTrace();
}
RMI Programming Lab 6 – JDBC – UPDATE OPERATION
1. RMI Interface
//RMIInterface.java
public interface RMIInterface extends Remote {
public String updateContact(String contactName, String phoneNo) throws
RemoteException;
}
2. RMI Server
//RMIServer.java
public class RMIServer extends UnicastRemoteObject implements RMIInterface {
static final String DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/phonedir";
Connection conn = null;
Statement stmt = null;
PreparedStatement prst;
ResultSet rs;
public RMIServer() throws RemoteException {
}
public String updateContact(String contactName, String phoneNo) throws
RemoteException {
String val = "", CPHONE = "";
try {
Class.forName(DRIVER);
conn = DriverManager.getConnection(DB_URL, "root", "");
stmt = conn.createStatement();
12. Assosa University College of Computing and Informatics
Department of Computer Science Distributed Systems Lab Manuallllllllllllll12
String sql = "SELECT *FROM contact WHERE phoneno = '" + phoneNo + "'";
rs = stmt.executeQuery(sql);
while (rs.next()) {
CPHONE = rs.getString("phoneno");
}
if (!phoneNo.intern().equals(CPHONE)) {
val = "0";
} else if (phoneNo.intern().equals(CPHONE)) {
prst = conn.prepareStatement("UPDATE contact SET contactname = '" +
contactName + "' WHERE phoneno = '" + phoneNo + "'");
prst.executeUpdate();
val = "1";
}
} catch (Exception ex) {
ex.printStackTrace();
}
return val;
}
public static void main(String[] args) {
try {
Registry r = LocateRegistry.createRegistry(1010);
RMIServer rs = new RMIServer();
r.rebind("x", rs);
System.out.println("Server Ready!");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
3. RMI Client
//RMIClient.java: Inside btnUpdateActionPerformed
try {
String contactName = txtName.getText();
String phoneNo = txtPhoneNo.getText();
RMIInterface ri = (RMIInterface) Naming.lookup("rmi://localhost:1010/x");
String result = ri.updateContact(contactName, phoneNo);
if (result.equals("1")) {
JOptionPane.showMessageDialog(this, "Contact Updated Successfully!", "Tele Dir:
Contact Updated.", JOptionPane.INFORMATION_MESSAGE);
} else if (result.equals("0")) {
JOptionPane.showMessageDialog(this, "Contact Doesn't Exist!", "Tele Dir: No
Contact.", JOptionPane.INFORMATION_MESSAGE);
}
} catch (Exception e) {
e.printStackTrace();
}
13. Assosa University College of Computing and Informatics
Department of Computer Science Distributed Systems Lab Manuallllllllllllll13
RMI Programming Lab 7 – JDBC – DELETE OPERATION
1. RMI Interface
//RMIInterface.java
public interface RMIInterface extends Remote {
public String deleteContact(String phoneNo) throws RemoteException;
}
2. RMI Server
//RMIServer.java
public class RMIServer extends UnicastRemoteObject implements RMIInterface {
static final String DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/phonedir";
Connection conn = null;
Statement stmt = null;
ResultSet rs;
public RMIServer() throws RemoteException {
}
public String deleteContact(String phoneNo) throws RemoteException {
String val = "", CPHONE = "";
try {
Class.forName(DRIVER);
conn = DriverManager.getConnection(DB_URL, "root", "");
stmt = conn.createStatement();
String sql = "SELECT *FROM contact WHERE phoneno = '" + phoneNo + "'";
rs = stmt.executeQuery(sql);
while (rs.next()) {
CPHONE = rs.getString("phoneno");
}
if (!phoneNo.intern().equals(CPHONE)) {
val = "0";
}
else if (phoneNo.intern().equals(CPHONE)) {
stmt = conn.createStatement();
String sql2 = "DELETE FROM contact WHERE phoneno = '"+phoneNo+"'";
stmt.executeUpdate(sql2);
val = "1";
}
14. Assosa University College of Computing and Informatics
Department of Computer Science Distributed Systems Lab Manuallllllllllllll14
} catch (Exception ex) {
ex.printStackTrace();
}
return val;
}
public static void main(String[] args) {
try {
Registry r = LocateRegistry.createRegistry(1010);
RMIServer rs = new RMIServer();
r.rebind("x", rs);
System.out.println("Server Ready!");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
3. RMI Client
//RMIClient.java: Inside btnDeleteActionPerformed
try {
String phoneNo = txtPhoneNo.getText();
RMIInterface ri = (RMIInterface) Naming.lookup("rmi://localhost:1010/x");
String result = ri.deleteContact(phoneNo);
if (result.equals("1")) {
JOptionPane.showMessageDialog(this, "Contact Deleted Successfully!", "Tele Dir:
Contact Deleted.", JOptionPane.INFORMATION_MESSAGE);
} else if (result.equals("0")) {
JOptionPane.showMessageDialog(this, "Contact Doesn't Exist!", "Tele Dir: No
Contact.", JOptionPane.INFORMATION_MESSAGE);
}
} catch (Exception e) {
e.printStackTrace();
}
15. Assosa University College of Computing and Informatics
Department of Computer Science Distributed Systems Lab Manuallllllllllllll15
RMI Programming Lab 8 – JDBC – SELECT OPERATION - LOGIN
1. RMI Interface
//RMIInterface.java
public interface RMIInterface extends Remote {
public String login(String username, String password) throws RemoteException;
}
2. RMI Server
//RMIServer.java
public class RMIServer extends UnicastRemoteObject implements RMIInterface {
static final String DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/phonedirectory";
Connection conn = null;
Statement stmt = null;
ResultSet rs;
public RMIServer() throws RemoteException {
}
public String login(String userName, String password) throws RemoteException {
String uname = "", pass = "", val="";
try {
Class.forName(DRIVER);
conn = DriverManager.getConnection(DB_URL, "root", "");
stmt = conn.createStatement();
String query = "SELECT * FROM useraccount WHERE username ='" + userName + "'";
rs = stmt.executeQuery(query);
while (rs.next()) {
uname = rs.getString("username");
pass = rs.getString("password");
}
if ((userName.intern().equals(uname.intern()) &&
(password.intern().equals(pass.intern())))) {
val = "1";
} else if ((!userName.intern().equals(uname.intern()) &&
(!password.intern().equals(pass.intern())))) {
val = "0";
}
16. Assosa University College of Computing and Informatics
Department of Computer Science Distributed Systems Lab Manuallllllllllllll16
conn.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
return val;
}
public static void main(String[] args) {
try {
Registry r = LocateRegistry.createRegistry(1010);
RMIServer rs = new RMIServer();
r.rebind("x", rs);
System.out.println("Server Ready!");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
4. RMI Client
//RMIClient.java: Inside btnDeleteActionPerformed
try {
String userName = txtUserName.getText();
String password = txtPassword.getText();
RMIInterface ri = (RMIInterface) Naming.lookup("rmi://localhost:1010/x");
String res = ri.login(userName, password);
if (res.equals("1")) {
frmViewAllContacts vac = new frmViewAllContacts();
vac.setVisible(true);
this.dispose();
} else if (res.equals("0")) {
JOptionPane.showMessageDialog(this, "Incorrect User Name or Password! Please
Try Again!", "Phone Directory.", JOptionPane.INFORMATION_MESSAGE);
}
} catch (Exception ex) {
ex.printStackTrace();
}