0% found this document useful (0 votes)
2 views

servletworkbench queries

The document provides SQL code to create databases and tables for four servlet-based applications: an expense tracker, a bank system, an employee management system, and a library management system. Each section includes SQL queries to create the necessary schema and tables, along with explanations of the columns for each table. It also includes notes on ensuring proper database configuration and user access.

Uploaded by

22eg105a63
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

servletworkbench queries

The document provides SQL code to create databases and tables for four servlet-based applications: an expense tracker, a bank system, an employee management system, and a library management system. Each section includes SQL queries to create the necessary schema and tables, along with explanations of the columns for each table. It also includes notes on ensuring proper database configuration and user access.

Uploaded by

22eg105a63
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1)servletproject1

Here is the SQL code to create the necessary tables for your servlet-based expense tracker, following the
format you provided. The schema name and table name are based on the information from your servlet code:

SQL Queries

1. Create the expensetracker schema (if it doesn't already exist):

sql
Copy code
CREATE DATABASE IF NOT EXISTS expensetracker;

2. Create the expenses table:

sql
Copy code
CREATE TABLE `expensetracker`.`expenses` (
`expense_id` INT NOT NULL AUTO_INCREMENT,
`user_id` INT NOT NULL,
`amount` DOUBLE NOT NULL,
`category` VARCHAR(255) NOT NULL,
`date` DATE NOT NULL,
PRIMARY KEY (`expense_id`)
);

Explanation of Columns:

 expense_id: Auto-incrementing primary key for unique identification of each expense.


 user_id: ID of the user who made the expense.
 amount: The amount of the expense (in numerical form).
 category: Category to which the expense belongs (e.g., "Food", "Transport", etc.).
 date: Date when the expense was incurred.

This table structure corresponds to the SQL operations defined in the servlet's methods for adding an
expense and viewing expenses by category.

Notes:

 If you also need a users table (for storing user data), you can create it similarly.
 Make sure the database is configured correctly and your
jdbc:mysql://localhost:3306/expensetracker connection works with the provided credentials
(root as the username and tiger as the password).

2)servletproject2
Here are the SQL queries to create the necessary tables for your servlet-based bank system, following the
format you provided. The schema name is bank and the table names are based on the servlet operations such
as creating accounts, deposits, withdrawals, and transactions.

SQL Queries

1. Create the bank schema (if it doesn't already exist):


sql
Copy code
CREATE DATABASE IF NOT EXISTS bank;

2. Create the accounts table:

sql
Copy code
CREATE TABLE `bank`.`accounts` (
`account_id` INT NOT NULL AUTO_INCREMENT,
`user_name` VARCHAR(255) NOT NULL,
`balance` DOUBLE NOT NULL DEFAULT 0,
PRIMARY KEY (`account_id`)
);

Explanation of Columns for accounts:

 account_id: Auto-incrementing primary key for each account.


 user_name: Name of the user who holds the account.
 balance: Account balance, initialized to 0 if not provided.

3. Create the transactions table:

sql
Copy code
CREATE TABLE `bank`.`transactions` (
`transaction_id` INT NOT NULL AUTO_INCREMENT,
`account_id` INT NOT NULL,
`type` ENUM('Deposit', 'Withdrawal') NOT NULL,
`amount` DOUBLE NOT NULL,
`transaction_date` DATE NOT NULL,
PRIMARY KEY (`transaction_id`),
FOREIGN KEY (`account_id`) REFERENCES `accounts`(`account_id`)
);

Explanation of Columns for transactions:

 transaction_id: Auto-incrementing primary key for each transaction.


 account_id: The account associated with the transaction (foreign key to accounts).
 type: The type of transaction (either 'Deposit' or 'Withdrawal').
 amount: The amount involved in the transaction.
 transaction_date: The date of the transaction (defaults to the current date).

Notes:

 Make sure your database user root has access to the bank schema and the database password is
correct (tiger).
 The transactions are recorded using account_id, ensuring that each deposit/withdrawal is tied to an
account.

3)servletproject3
Here are the SQL queries to create the necessary tables for your servlet-based employee management
system, following the same format as the previous requests. The schema name is employee_management,
and the relevant table is employees.
SQL Queries

1. Create the employee_management schema (if it doesn't already exist):

sql
Copy code
CREATE DATABASE IF NOT EXISTS employee_management;

2. Create the employees table:

sql
Copy code
CREATE TABLE `employee_management`.`employees` (
`employee_id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL,
`department_id` INT NOT NULL,
`salary` DOUBLE NOT NULL,
PRIMARY KEY (`employee_id`)
);

Explanation of Columns for employees:

 employee_id: Auto-incrementing primary key for each employee.


 name: Name of the employee.
 email: Email address of the employee.
 department_id: Department to which the employee belongs.
 salary: Salary of the employee.

Make sure the employee_management database exists, and ensure the user root has appropriate access to it,
with the correct password (tiger).

4)servletproject4
Here are the SQL queries to create the necessary tables for your servlet-based library management system,
following the same format as the previous requests. The schema name is library, and the relevant tables
are books, borrowers, and lending.

SQL Queries

1. Create the library schema (if it doesn't already exist):

sql
Copy code
CREATE DATABASE IF NOT EXISTS library;

2. Create the books table:

sql
Copy code
CREATE TABLE `library`.`books` (
`book_id` INT NOT NULL AUTO_INCREMENT,
`title` VARCHAR(255) NOT NULL,
`author` VARCHAR(255) NOT NULL,
`publisher` VARCHAR(255),
`quantity` INT NOT NULL,
PRIMARY KEY (`book_id`)
);

3. Create the borrowers table:

sql
Copy code
CREATE TABLE `library`.`borrowers` (
`borrower_id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`email` VARCHAR(255),
`phone` VARCHAR(15),
PRIMARY KEY (`borrower_id`)
);

4. Create the lending table:

sql
Copy code
CREATE TABLE `library`.`lending` (
`lending_id` INT NOT NULL AUTO_INCREMENT,
`book_id` INT NOT NULL,
`borrower_id` INT NOT NULL,
`issue_date` DATE NOT NULL,
`return_date` DATE,
PRIMARY KEY (`lending_id`),
FOREIGN KEY (`book_id`) REFERENCES `books` (`book_id`),
FOREIGN KEY (`borrower_id`) REFERENCES `borrowers` (`borrower_id`)
);

Explanation of Tables:

1. books: Stores information about books in the library (ID, title, author, publisher, and quantity
available).
2. borrowers: Stores information about borrowers (ID, name, email, phone).
3. lending: Records the transactions of borrowing books (ID, book ID, borrower ID, issue date, and
return date).

Ensure the library database exists and the root user has the appropriate permissions to access and modify
it.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy