Write a Java program using JDBC to manage saving accounts of a bank. Make necessary assumptions. Make provisions of exception handling in your program.
Sure! Here’s a detailed Java program using JDBC to manage saving accounts for a bank. This program will include operations such as creating an account, depositing money, withdrawing money, and viewing account details. I will also handle exceptions to ensure the program operates smoothly.
### Java Program Using JDBC for Bank Account Management
Assumptions:
1. We are using a MySQL database.
2. The database has a table named `accounts` with columns: `account_id`, `account_holder`, `balance`.
Database Table Creation SQL:
```sql
CREATE TABLE accounts (
account_id INT AUTO_INCREMENT PRIMARY KEY,
account_holder VARCHAR(100),
balance DECIMAL(15, 2)
);
```
Java Program:
```java
import java.sql.*;
public class BankAccountManager {
private static final String URL = "jdbc:mysql://localhost:3306/bank";
private static final String USER = "root";
private static final String PASSWORD = "password";
// Establish database connection
private Connection connect() throws SQLException {
return DriverManager.getConnection(URL, USER, PASSWORD);
}
// Create a new account
public void createAccount(String holder, double initialBalance) {
String sql = "INSERT INTO accounts (account_holder, balance) VALUES (?, ?)";
try (Connection conn = connect(); PreparedStatement __________ _____ ______ ________ _____ ______ _______ ________ _________ _________ _______.
_____ _________ _________ _________ _____ __________ __________ ____.
___ ___ ________ _________ ________ _________ ____ __________ ______ ______ ___.
____ _________ _____ ______ _______.
________ ____ ____ ______ _______ __________.
________ _______ ___ ________ ________ _______ ____ ________ ________ _________.
_____ ___ __________ ________ _______ ________ _______.
________ _______ _______ _______ ________ _______ _________ _____ _______ ____.
_____ ___ _______ __________ ____ __________.
______ _____ ______ __________ _______.
_________ ______ _____ ______ __________ ________ _________ _______ __________ _______ __________.
___ _________ ___ _______ _____ _______.
________ _______ _________ __________ __________ _________ ___ _____ ______ _____ _______ ________.
__________ ______ _________ ____ ________ ___ ________ _______ ___ __________.
_________ ______ __________ ________ ______ ____.
_______ ______ _______ _____ ___ _________ ________ ____ _________ __________.
___ ________ __________ ______ ___ _______ __________ _________ _____.
________ ___ _________ _________ _______ ___ _______ _______.
_____ ________ _________ _________ _________ _________ ___.
____ _________ _______ _______ _______ ________ ____ ______ _______.
________ ____ ___ _______ _________ ________.
______ _______ ____ ______ ______ ___.
___ _________ ___ ________ ____ ________ ___ ________ ______ _____ ______.
_____ _________ ________ ______ ____ ______ ____ _________ ____ _______.
____ _____ _______ _______ ________.
_______ ____ ___ _______ ____ ________ ____ ____ _____ __________ ___.
____ _________ __________ _________ ______ ____ _________ _________ _______ _________.
_______ ______ ______ _________ ___ _____ ___ _________ ____ ______ ______ ______.
_____ _______ ________ _________ ____ _____ ___ _____ ____ _________.
____ _________ ____ ____ ___ _________ _____ ____ __________.
___ __________ _____ __________ __________.
___ _________ _______ ________ ______.
_______ _______ _______ _______ ___ ______ __________ ________.
___ ________ ______ ___ ____ _____ _________ ___ __________ __________ ______ ________.
_______ ________ _______ _______ ________.
_______ _______ _____ _________ ________ __________ _____ _______ ________ ________ ____.
_____ _____ _____ _________ _________ __________.
____ __________ _______ _______ ________ ______ ________ __________ ____ ____ _______ _____.
________ ________ ___ ___ __________ ______ ________ _________ ___.
___ _____ _______ ____ ____ ___ _____ __________ ________ _______ __________.
_____ _____ _____ __________ __________ ______ ________ ________ ______ _________ ________ ________.
______ ___ ______ ____ __________ _________ ______ _____.
___ ___ ___ ____ _____.
_________ __________ ________ ________ ______ ______ _____ ________ _______.
_______ ________ _________ _____ ___ _____.
______ ____ _______ _____ ___ _____.
________ _______ ___ _____ ___ _____ ____ _________ ______ ______ ______.
________ ________ _________ ___ ________ ____ _________ ___ _________.
______ ______ __________ _____ ______.
________ ______ ___ _____ __________ __________ ___ _____.
________ ____ ____ _________ ___ ______.
____ __________ ___ ____ ________ ____ __________ ____.
_______ ___ _________ ____ ________.
________ _________ ___ ______ _________.
_________ __________ ___ _________ __________ _____ __________ ___ ___ _____ __________.
_______ _____ __________ ___ _________ ___.
__________ _______ ____ _____ ______ __________ _______ ____ _______ __________.
_____ __________ _________ ____ _________ _____ _____ ________ ______.
____ ________ ____ _______ ____.
___ ___ _______ ______ ______ _____ ________ ______ ______.
_________ ________ ____ __________ ____.
____ ____ _____ __________ ________ ________ __________ __________ ____ ______ _______.
___ __________ _______ _____ ______ ____ ________ _________.
________ _____ ___ __________ _____.
__________ _______ _________ _______ _____.
_____ _________ _____ ____ ___ ________ __________ ____ _______.
________ ______ _____ ___ ___ ____ _________ ___ _____ __________ _____ ____.
_________ ____ _______ ______ _______ ________ _____ _______ _______ ______ ______.
__________ ________ __________ _________ ______ ________ _________ ___ ______ ___ _______ _________.
_____ __________ _________ _________ _____ ________ _____ ____ ___.
_______ _________ _____ ________ ____ __________ ___.
__________ _________ _____ _____ _______ _____ ______.
__________ _______ ______ __________ _____ ____.
_____ ________ ________ _________ ______ ______ ___.
_____ ___ ______ _____ _________ ______.
_________ _____ _________ ______ _____ _______ _________ _____.
_______ ___ ___ _______ ________ ____.
______ ____ __________ ______ _________ ______ ______ _____.
__________ ___ ___ _________ ______ _______.
______ _____ ______ __________ _____ ______ ________.
_______ ____ ___ __________ ______ _________.
________ ______ ______ ______ ____ _________ ____ ___.
______ __________ ___ ______ _______ ____.
_____ ____ _________ ________ _________ _____ ______ _________.
______ _______ _________ ____ _________ _____ _______ ________ __________ _____.
______ _____ _______ _____ _______.
_____ ________ _____ ____ _______.
___ ________ ________ ____ __________ _____ _____ __________ __________ ___ _______ __________.
____ _________ _______ ___ ________ _______ ___ __________ ________ ________.
______ __________ ________ _______ _________.
________ ___ ____ ________ _________ ________.
____ ___ ________ _____ _________ ______ ________ _________ _____ _________ ______.
_________ _________ __________ ______ _______ ______ _____ __________.
____ __________ __________ _______ _____ ____ _____ _____ __________ ____ _________.
_____ _______ __________ ___ ______ _______ ______ _______ ____ _____ _______ _______.
_______ _______ __________ ___ ____.
___ ___ ______ _____ _________ _____.
______ _______ ________ ______ ______ ___ __________ _________.
__________ ________ _____ __________ _____ ____ ______ ____ ________.
__________ ____ ___ ___ _______ __________ _______ __________ _________.
_________ ____ ___ ________ _________ ____ _____.
_________ _____ ______ _______ _________.
_______ _______ ____ ___ _________ _________ __________ ________ ________ ____ _____.
________ __________ ______ _____ _____ ______ ___ _______ __________.
________ _________ ___ _______ ____ ___ ___.
_______ _________ ___ ___ ________ __________ ________ ________ ___ ____.
_____ _________ _____ _____ _____.
______ _________ ________ ____ _____ _______.
____ _____ __________ ____ ____ ______ ______ ____ ________.
_____ __________ __________ _____ _______ _____ ____.
Get Full Answer on WhatsApp