Question #230499

How do we provide security to RMI classes? Write a program to implement Simple Student database application using RMI. Remote client consist of GUI for performing different database operations (For ex. Insert, delete, update) and retrieving data through RMI.


Expert's answer

Firstly, create class Student and an interface to invoke the following implementation:

import java.sql.*; 
import java.util.*;  






//Implementing an interface StudentDatabase.
public class simpleExample implements StudentDatabase {  
   
   //Interface method is implemented
   public List<Student> getStudents() throws Exception {  
//Creating Array of students     
 List<Student> list = new ArrayList<Student>();   
    
       
      String jdbcDriver = "com.mysql.jdbc.Driver";   
      String databaseURL = "jdbc:mysql://localhost:3306/details";  
      
      // Database username and password 
      String user = "root"; 
      String pass = "pass_word";  
      
      Connection conn = null//Used to create connection to the database
//For quering the database      
Statement stmt = null;  
      
      //A driver for connecting to the database
      Class.forName("com.mysql.jdbc.Driver");   //JDBC driver
      
      //Opening connection to the database      
      conn = DriverManager.getConnection(Database_URL, user, pass); 
      System.out.println("Successfully connection to the database");  
      
      //Start of executing queries
      System.out.println("A statement is being created..."); 
      
      stmt = conn.createStatement();  
      String query1 = "SELECT * FROM student_data"; 
      ResultSet rs1 = stmt.executeQuery(query1);  
      
      //Extracting rows from the ResultSet statement 
      while(rs1.next()) { 
         
         int studentId  = rs1.getInt("id"); 
         
         String studentName = rs1.getString("name"); 
         String studentBranch = rs1.getString("branch"); 
         
         int studentPercent = rs1.getInt("percentage"); 
         String studentEmail = rs1.getString("email");  
         
      //Creating an object of Student class
         Student student = new Student(); 
         student.setID(id); 
         student.setName(name); 
         student.setBranch(branch); 
         student.setPercent(percent); 
         student.setEmail(email); 
         list.add(student); 
      } 
      rs1.close(); 
      return list;     
   }  
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS