Like the Indian Premier League (IPL) which happens during April & May every year. Our team organizes ProGrad Premier League at the same time for all the Cricketers in our team. Our PPL schema is a complete repository of limited-over format of Cricket, that includes details like teams competing, player representing each team, scoring details, umpire details etc.
Can you help out with the below task and take our database creation to completion?
Fork this repo
Clone this repo
Practice Java JDBC - class and object, Statements, Connections and CRUD.
Upon completion, run the following commands:
git add .
git commit -m "ProGrad ID"
git push origin master
And finally, create a pull request so your ProGrad Mentor (PM) can review your work.
- Do not modify the entire code.
- Edit the code as per the instructions.
- Go to Java Resources -> src folder.
- You database connection code should exist inside the utlity package.
- Your CREATE, READ, UPDATE and DELETE code should exist inside the dao package.
- Once the progressions are completed follow the instructions to run the application and test your code.
- Add appropriate jars to your project directory.
- To add dependencies, right click on your project, select build path - configure build path - select libraries tab - select add external jars and add the downloaded jar files.
If you haven't downloaded OJDBC driver (ojdbc6.jar), then download using this link [https://www.oracle.com/database/technologies/jdbcdriver-ucp-downloads.html]
- Right click on src folder and select new - file and name it as jdbc.properties.
- You can use the jdbc properties given below in the NOTE section.
- Create a class called as
ConnectionManager
inside the utility package. - Create a method public static Connection getConnection() which returns a connection object.
- Use the method public static Properties loadPropertiesFile() to load the jdbc properties from the jdbc.properties file.
- Create a class called as
skill
with below attributes,- skillld - Long
- skillName - String
- Include appropriate getters and setters.
- Include getter and setter method for all the attributes Include constructor with below arguments, public Skill(skillId, skillName).
- Create a dao-class called as
SkillDAO
with the below method,- public Skill getSkillBylD(Long id) - Method used to fetch the skill information from the database based on the skill id.
- Create a class called as
Player
with below attributes,- playerld - Long
- name - String
- country - String
- skill - Skill
- Include getter and setter method for all the attributes.
- Include constructor with below arguments - public Player(Long playerld,String name, String country,Skill skill)
- Create a class called as
PlayerDAO
with below methods,- public List< Player > getAllPlayers() - Method used to fetch all the players and their corresponding skill from the database.
- Create a controller called as Main inside the controller package.
- Create appropriate objects for the classes - Player, PlayerDAO, Skill and SkillDAO.
- Refer sample output given below for output format.
Use the below code to retreive the connection details from jdbc.properties to establish connection
public static Properties loadPropertiesFile() throws Exception {
Properties prop = new Properties();
InputStream in = ConnectionManager.class.getClassLoader().getResourceAsStream("jdbc.properties");
prop.load(in);
in.close();
return prop;
}
Create a file called as jdbc.properites. To create a file right click on the application - new - file - name the file as jdbc.properties.
jdbc.properties
#JDBC properties entry for ORACLE server
driver = oracle.jdbc.OracleDriver
url=jdbc:oracle:thin:@localhost:1521:xe
username=your_username
password=your_password
Sample Output
List of all player and their skill
Id Name Country Skill
26 Aaron Finch Australia Batting
80 AB de Villiers South Africa Batting
82 Abu Nechim India Bowling
85 Adam Milne New Zealand Bowling
16 Akshdeep Nath India All Rounder
Happy Coding ❤️