Sequential Data Reading
public static void authenticateUser(String username, String password) throws Exception {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "root", "password");
Statement statement = conn.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM accounts");
boolean isAuthenticated = false;
while (resultSet.next() && !username.equals(resultSet.getString(1))) {
System.out.println(resultSet.getInt(1) + " " + resultSet.getString(2) + " " + resultSet.getString(3) + " " + resultSet.getInt(4) + " " + resultSet.getString(5));
}
System.out.println("Account ID: " + resultSet.getInt(1));
System.out.println("Password: " + resultSet.getString(2));
if (password.equals(resultSet.getString(2))) {
isAuthenticated = true;
}
resultSet.close();
statement.close();
conn.close();
}
Enserting a Row
public static void addAccount(int id, String password, String email, int status) throws Exception {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "root", "password");
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO accounts VALUES (?, ?, ?, ?, ?)");
preparedStatement.setInt(1, id);
preparedStatement.setString(2, password);
preparedStatement.setString(3, email);
preparedStatement.setInt(4, status);
preparedStatement.setString(5, null); // optional field
preparedStatement.executeUpdate();
preparedStatement.close();
connection.close();
}
Interface Screenshots


Serilaization & Deserializasion
Serialization converts an object into a byte stream, which can later be deserialized back into a copy of the original object (i.e., encoding all data of a class and then restoring it to a class instance).
package util; // Note: every piece of code gets serialized
import java.io.Serializable;
public class SerializableData implements Serializable { // No methods need to be implemented
private String content;
public SerializableData(String content) {
this.content = content;
}
public SerializableData() {}
public String getContent() {
return content;
}
}