Remember your client Mr. Alex?
Well, he loves your work and is back for your help. He's reworking on the same project with the help of databases. Can you look into his requirements & sort things out? You can start building the project on top of Stage - 3
Fork this repo
Clone this repo
Practice Java JDBC - connections, Statement and ResultSet.
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.
- Your database connection code should exist inside the utlity package.
- Your crud operations should go inside the dao package.
- Create the connection object in the controller and call the respective methods.
- Once the progressions are completed follow the instructions to run the application and test your code.
- Add appropriate jars to your project directory.
Download ojdbc6.jar from the given 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 model class called as `Blog' inside the model package with the following arguments,
- int blogId
- String blogTitle;
- String blogDescription;
- LocalDate postedOn;
- int blogId
- Include appropriate getters and setters method.
- Create an interface called BlogDaoInterface inside the dao package with the following methods,
- void insertBlog(Blog blog)
- List selectAllBlogs()
- Blog selectBlog(int blogid);
- boolean deleteBlog(int id)
- boolean updateBlog(Blog blog)
- Create a dao-class called BlogDaoImpl inside the dao package.
- It should implement the BlogDaoInterface.
- Implement the following methods,
- void insertBlog(Blog blog) - method to insert the blog into the database.
- List selectAllBlogs() - method to retrieve the blogs from the database.
- Blog selectBlog(int blogid) - method to retrieve a selected blog based on its id.
- boolean deleteBlog(int id) - method to delete a selected blog.
- boolean updateBlog(Blog blog) - method to update a blog.
- Do not modify any code in EditViewController, UpdateBlogController and DeleteBlogController.
- Right click the project - select run as run on server.
- Login with the username and password.
- Click Edit button to edit your post.
- Click Delete button to delete the selected blog.
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
Happy Coding ❤️