Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.ResourceBundle; public class DbConnection { public static Connection getConnection() throws ClassNotFoundException, SQLException { ResourceBundle rb= ResourceBundle.getBundle(mysql); String url

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.util.ResourceBundle;

public class DbConnection {

public static Connection getConnection() throws ClassNotFoundException, SQLException {

ResourceBundle rb= ResourceBundle.getBundle("mysql");

String url = rb.getString("db.url");

String username = rb.getString("db.username");

String password = rb.getString("db.password");

//fill the code

}

}

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.sql.SQLException;

import java.util.ArrayList;

import java.util.Iterator;

import java.util.List;

public class Main {

public static void main(String[] args) throws NumberFormatException, IOException, ClassNotFoundException, SQLException {

RoleDAO roleDAO = new RoleDAO();

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

PrivilegeDAO privilegeDAO = new PrivilegeDAO();

List privileges = privilegeDAO.getAllPrivileges();

System.out.println("List of privileges :");

System.out.format("%-15s %s ","Privilege ID","Privilege Name");

for(int i=0;i

System.out.format("%-15s %s ",privileges.get(i).getId(),privileges.get(i).getName());

}

System.out.println("Enter number of new Roles to be created :");

Integer n = Integer.parseInt(br.readLine());

System.out.println("Enter the role and privileges :");

//fill the code

System.out.println("Enter the Role :");

String rol = br.readLine();

System.out.println("Privileges for "+rol+" :");

//fill the code

}

}

db.url=jdbc:mysql://localhost:3306/role_privilege

db.username=root

db.password=test

public class Privilege {

private Integer id;

private String name;

public Privilege(){}

public Privilege(String name){

this.name = name;

}

public Privilege(Integer id, String name) {

this.id = id;

this.name = name;

}

public Integer getId() {

return id;

}

public void setId(Integer id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

}

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import java.util.List;

public class PrivilegeDAO {

public List getAllPrivileges() throws SQLException, ClassNotFoundException {

//fill the code

}

}

import java.util.ArrayList;

public class Role {

private Integer id;

private String name;

private ArrayList privilegeList;

public Role(){}

public Role(String name) {

this.name = name;

}

public Role(Integer id, String name) {

this.id = id;

this.name = name;

}

public Role(Integer id, String name, ArrayList privilegeList) {

this.id = id;

this.name = name;

this.privilegeList = privilegeList;

}

public Integer getId() {

return id;

}

public void setId(Integer id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public ArrayList getPrivilegeList() {

return privilegeList;

}

public void setPrivilegeList(ArrayList privilegeList) {

this.privilegeList = privilegeList;

}

}

import java.sql.*;

import java.util.ArrayList;

import java.util.Iterator;

import java.util.List;

public class RoleDAO {

public void createRole(Role roleIns, ArrayList privilegeList) throws SQLException, ClassNotFoundException {

//fill the code

}

public List getPreviligeByRole(String role) throws ClassNotFoundException, SQLException {

//fill the code

}

}

drop table if exists privilege;

create table privilege

(id int not null AUTO_INCREMENT,

name varchar(255) not null,primary key(id));

insert into privilege(name) values('Create');

insert into privilege(name) values('Process');

insert into privilege(name) values('Schedule');

insert into privilege(name) values('Cancel');

insert into privilege(name) values('View');

drop table if exists role;

create table role

(id int not null AUTO_INCREMENT,

name varchar(255) not null,primary key(id));

drop table if exists role_privilege;

create table role_privilege

(role_id int not null references role(id),

privilege_id int not null references privilege(id),

primary key(role_id,privilege_id));

Use above code for implementation and refer Q10 image for complete question and specifiaction

New Roles may emerge as the functionalities of the Shipment Management System expands. Wrte a program that will create

image text in transcribed
Click here to download mysqlConnector.l program should midway lot al the packages in the appam. then put the Create a class Privilege with below attributes. Include getter and setter method for al the atributes Include default contractor with and canserveto create a class Role with below attributes. . Inanger id . String name Create a class PrivtegeDAD with following methods This method is used to fete Create a class beCammesses with following method: Method Description adore state Connection gutconnection This method is used to correct the java app Here register the JDBC driver for the sookcatic TWO Layer - Data a delete ary data In the Total properties: DELUSERNAME= $17'S DELUSERNAME) Use the below code to retrieve the cons String passand " Is getsring( DE_PASSWORDX Table Structure: DENS create verges god latte and cekren purses der ased on the id. Display the Role details in ascending order based on the id

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions