Online Voting System in my facing challenges.....
1. JDBC Connection & SQL Errors My first roadblock wasn't even logic — it was just getting connected. I kept hitting: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure ** What was going wrong:** Wrong JDBC URL format (missing useSSL=false or timezone parameter caused issues on newer MySQL versions) MySQL service not running Driver JAR not added to the classpath…
The online voting system is encountering several technical challenges that need to be addressed. The primary issue is establishing a connection to the MySQL database, which is causing communication failures. This appears to be due to an incorrect JDBC URL format or missing parameters in the connection string. The developer resolved this by ensuring the correct URL format, including the `useSSL=false` and `serverTimezone=UTC` parameters, and properly adding the MySQL driver JAR to the classpath.
Another significant challenge is preventing users from casting duplicate votes. The developer addressed this by adding a `has_voted` boolean column to the voters table. Before a user can cast a vote, the system checks this flag in a database query. If the user has already voted, the vote is not accepted. Additionally, a UNIQUE constraint was implemented at the database level to prevent duplicate entries, serving as a backup to the application logic.
The developer initially had scattered database queries in their main class, making it difficult to test and maintain. To improve code organization, they refactored the system into a DAO (Data Access Object) pattern. The final structure includes separate DAO interfaces and implementation classes for handling voter verification, candidate data, vote casting and counting, and managing database connections. This separation allows for easier debugging and future database swapping with minimal code changes.
Lastly, when generating the final vote results, the developer faced an issue with incomplete or garbled output due to improper handling of the file writer. The problem was resolved by using a `BufferedWriter` with a `try-with-resources` statement, which automatically closes the writer after the code block is executed, ensuring that all data is properly written to the file.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.