package BookManagement;
import [Link].*;
import [Link];
public class Book {
static String URL =
"jdbc:mysql://localhost:3306/BookManagement";
static String USER = "root";
static String PASS = "763155";
//-----------------------------------------------------
--------------------------------
// insert book
public static void insertBook() {
Scanner sc = new Scanner([Link]);
try {
Connection con =
[Link](URL, USER, PASS);
Statement stmt = [Link]();
[Link]("-------------- INSERT
BOOK -----------------");
try {
[Link]("Enter the ID : ");
int id = [Link]();
[Link]();
[Link]("Name : ");
String name = [Link]();
[Link]("Author Name : ");
String author = [Link]();
[Link]("Price : ");
int price = [Link]();
[Link]("Number Of Page : ");
int pages = [Link]();
[Link]();
[Link]("Publisher : ");
String publisher = [Link]();
[Link]("Publishing Date (yyyy-MM-
dd): ");
String date = [Link]();
[Link]("Category : ");
int category = [Link]();
[Link]();
[Link]("Language : ");
String language = [Link]();
String sql = "INSERT INTO Book VALUES (" +
id + ",'" + name + "','" + author + "'," + price + ","
+ pages + ",'" +
publisher + "','" + date + "'," +
category + ",'" + language + "')";
int row = [Link](sql);
[Link]("Book Inserted
Successfully "+row+" Row !");
}catch (Exception e ){
[Link]("Please Enter Valid
Input");
}
} catch (Exception e) {
[Link]();
}
}
//-----------------------------------------------------
-----------------------------
// Update data
public static void updateBook() {
Scanner sc = new Scanner([Link]);
try {
Connection con =
[Link](URL, USER, PASS);
Statement stmt = [Link]();
[Link]("-------------- UPDATE
BOOK -----------------");
try {
[Link]("Enter Book ID : ");
int id = [Link]();
[Link]();
[Link]("What do you want to
update");
[Link]("1. Name");
[Link]("2. Author Name");
[Link]("3. Price");
[Link]("4. Pages");
[Link]("5. Publisher");
[Link]("6. Language");
[Link]("Enter choice : ");
int choice = [Link]();
[Link]();
String sql = "";
switch (choice) {
case 1:
[Link]("Enter New Name :
");
String name = [Link]();
sql = "UPDATE Book SET Name='" +
name + "' WHERE ID=" + id;
[Link]("Name "+name);
break;
case 2:
[Link]("Enter New Author
Name : ");
String author = [Link]();
sql = "UPDATE Book SET
Author_Name='" + author + "' WHERE ID=" + id;
[Link](" Author Name
"+author);
break;
case 3:
[Link]("Enter New Price :
");
int price = [Link]();
sql = "UPDATE Book SET Price=" +
price + " WHERE ID=" + id;
[Link](" Price "+price);
break;
case 4:
[Link]("Enter New Pages :
");
int pages = [Link]();
sql = "UPDATE Book SET
Number_Of_Page=" + pages + " WHERE ID=" + id;
[Link](" Number Of Page
"+pages);
break;
case 5:
[Link]("Enter New
Publisher : ");
String publisher = [Link]();
sql = "UPDATE Book SET Publisher='"
+ publisher + "' WHERE ID=" + id;
[Link](" Publisher
"+publisher);
break;
case 6:
[Link]("Enter New
Language : ");
String language = [Link]();
sql = "UPDATE Book SET Language='"
+ language + "' WHERE ID=" + id;
[Link](" Language
"+language);
break;
default:
[Link]("Invalid
Choice");
return;
}
int rows = [Link](sql);
if (rows > 0)
[Link](" Successfully
Update");
else
[Link]("Book ID Not
Found");
}catch (Exception e ){
[Link]("Please Enter Valid
Input");
}
} catch (Exception e) {
[Link]();
}
}
// -------------------------------------------------
----------------------------------
// Delete data
public static void deleteBook() {
Scanner sc = new Scanner([Link]);
try {
Connection con =
[Link](URL, USER, PASS);
Statement stmt = [Link]();
[Link]("--------------
DELETE BOOK -----------------");
try{
[Link]("Enter Book ID to
Delete : ");
int id = [Link]();
String sql = "DELETE FROM Book WHERE
ID=" + id;
int rows = [Link](sql);
if (rows > 0)
[Link]("Book Deleted
Successfully"+rows+"Row !");
else
[Link]("Book ID Not
Found");
}catch (Exception e ){
[Link]("Please Enter
Valid Input");
}
} catch (Exception e) {
[Link]();
}
}
//-----------------------------------------------------
------------------------------------
// SHOW DATA
public static void ShowData() {
Scanner sc = new Scanner([Link]);
try {
Connection con =
[Link](URL, USER, PASS);
Statement stmt = [Link]();
String sql;
[Link]("-------------- SHOW
BOOK -----------------");
try{
[Link]("Show All data :
Yes/No:");
String Choooe =
[Link]().toUpperCase().trim();
if ([Link]("YES")) {
sql = "SELECT * FROM Book";
} else
{
[Link]("Enter Book ID : ");
int id = [Link]();
sql = "SELECT * FROM Book WHERE ID=" +
id;
ResultSet rs = [Link](sql);
while ([Link]()) {
//ID, Name, Author_Name, Price,
Number_Of_Page, Publisher, Publishing_Date, Category,
Language
int ID = [Link]("ID");
String name = [Link]("Name");
String author =
[Link]("Author_Name");
int price = [Link]("Price");
int pages =
[Link]("Number_Of_Page");
String publisher =
[Link]("Publisher");
String date =
[Link]("Publishing_Date");
int category = [Link]("Category");
String language =
[Link]("Language");
[Link](ID + " | " + name +
" | " + author + " | " + price + " | " + pages + " | "
+ publisher + " | " + date + " | " + category + " | " +
language);
}
}catch (Exception e ){
[Link]("Please Enter Valid
Input");
} catch (Exception e) {
[Link]();
}
}
package BookManagement;
import [Link].*;
import [Link];
public class Book {
static String URL =
"jdbc:mysql://localhost:3306/BookManagement";
static String USER = "root";
static String PASS = "763155";
//-----------------------------------------------------
--------------------------------
// insert book
public static void insertBook() {
Scanner sc = new Scanner([Link]);
try {
Connection con =
[Link](URL, USER, PASS);
Statement stmt = [Link]();
[Link]("-------------- INSERT
BOOK -----------------");
try {
[Link]("Enter the ID : ");
int id = [Link]();
[Link]();
[Link]("Name : ");
String name = [Link]();
[Link]("Author Name : ");
String author = [Link]();
[Link]("Price : ");
int price = [Link]();
[Link]("Number Of Page : ");
int pages = [Link]();
[Link]();
[Link]("Publisher : ");
String publisher = [Link]();
[Link]("Publishing Date (yyyy-MM-
dd): ");
String date = [Link]();
[Link]("Category : ");
int category = [Link]();
[Link]();
[Link]("Language : ");
String language = [Link]();
String sql = "INSERT INTO Book VALUES (" +
id + ",'" + name + "','" + author + "'," + price + ","
+ pages + ",'" +
publisher + "','" + date + "'," +
category + ",'" + language + "')";
int row = [Link](sql);
[Link]("Book Inserted
Successfully "+row+" Row !");
}catch (Exception e ){
[Link]("Please Enter Valid
Input");
}
} catch (Exception e) {
[Link]();
}
}
//-----------------------------------------------------
-----------------------------
// Update data
public static void updateBook() {
Scanner sc = new Scanner([Link]);
try {
Connection con =
[Link](URL, USER, PASS);
Statement stmt = [Link]();
[Link]("-------------- UPDATE
BOOK -----------------");
try {
[Link]("Enter Book ID : ");
int id = [Link]();
[Link]();
[Link]("What do you want to
update");
[Link]("1. Name");
[Link]("2. Author Name");
[Link]("3. Price");
[Link]("4. Pages");
[Link]("5. Publisher");
[Link]("6. Language");
[Link]("Enter choice : ");
int choice = [Link]();
[Link]();
String sql = "";
switch (choice) {
case 1:
[Link]("Enter New Name :
");
String name = [Link]();
sql = "UPDATE Book SET Name='" +
name + "' WHERE ID=" + id;
[Link]("Name "+name);
break;
case 2:
[Link]("Enter New Author
Name : ");
String author = [Link]();
sql = "UPDATE Book SET
Author_Name='" + author + "' WHERE ID=" + id;
[Link](" Author Name
"+author);
break;
case 3:
[Link]("Enter New Price :
");
int price = [Link]();
sql = "UPDATE Book SET Price=" +
price + " WHERE ID=" + id;
[Link](" Price "+price);
break;
case 4:
[Link]("Enter New Pages :
");
int pages = [Link]();
sql = "UPDATE Book SET
Number_Of_Page=" + pages + " WHERE ID=" + id;
[Link](" Number Of Page
"+pages);
break;
case 5:
[Link]("Enter New
Publisher : ");
String publisher = [Link]();
sql = "UPDATE Book SET Publisher='"
+ publisher + "' WHERE ID=" + id;
[Link](" Publisher
"+publisher);
break;
case 6:
[Link]("Enter New
Language : ");
String language = [Link]();
sql = "UPDATE Book SET Language='"
+ language + "' WHERE ID=" + id;
[Link](" Language
"+language);
break;
default:
[Link]("Invalid
Choice");
return;
}
int rows = [Link](sql);
if (rows > 0)
[Link](" Successfully
Update");
else
[Link]("Book ID Not
Found");
}catch (Exception e ){
[Link]("Please Enter Valid
Input");
}
} catch (Exception e) {
[Link]();
}
}
// -------------------------------------------------
----------------------------------
// Delete data
public static void deleteBook() {
Scanner sc = new Scanner([Link]);
try {
Connection con =
[Link](URL, USER, PASS);
Statement stmt = [Link]();
[Link]("--------------
DELETE BOOK -----------------");
try{
[Link]("Enter Book ID to
Delete : ");
int id = [Link]();
String sql = "DELETE FROM Book WHERE
ID=" + id;
int rows = [Link](sql);
if (rows > 0)
[Link]("Book Deleted
Successfully"+rows+"Row !");
else
[Link]("Book ID Not
Found");
}catch (Exception e ){
[Link]("Please Enter
Valid Input");
}
} catch (Exception e) {
[Link]();
}
}
//-----------------------------------------------------
------------------------------------
// SHOW DATA
public static void ShowData() {
Scanner sc = new Scanner([Link]);
try {
Connection con =
[Link](URL, USER, PASS);
Statement stmt = [Link]();
String sql;
[Link]("-------------- SHOW
BOOK -----------------");
try{
[Link]("Show All data :
Yes/No:");
String Choooe =
[Link]().toUpperCase().trim();
if ([Link]("YES")) {
sql = "SELECT * FROM Book";
} else
{
[Link]("Enter Book ID : ");
int id = [Link]();
sql = "SELECT * FROM Book WHERE ID=" +
id;
ResultSet rs = [Link](sql);
while ([Link]()) {
//ID, Name, Author_Name, Price,
Number_Of_Page, Publisher, Publishing_Date, Category,
Language
int ID = [Link]("ID");
String name = [Link]("Name");
String author =
[Link]("Author_Name");
int price = [Link]("Price");
int pages =
[Link]("Number_Of_Page");
String publisher =
[Link]("Publisher");
String date =
[Link]("Publishing_Date");
int category = [Link]("Category");
String language =
[Link]("Language");
[Link](ID + " | " + name +
" | " + author + " | " + price + " | " + pages + " | "
+ publisher + " | " + date + " | " + category + " | " +
language);
}
}catch (Exception e ){
[Link]("Please Enter Valid
Input");
} catch (Exception e) {
[Link]();
}
}
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
try {
int ch;
do {
[Link]("1. Insert
Book");
[Link]("2. Update
Book");
[Link]("3. Delete
Book");
[Link]("4. Show
Book");
[Link]("Enter choice :
");
int choice = [Link]();
if (choice == 1)
insertBook();
else if (choice == 2)
updateBook();
else if (choice == 3)
deleteBook();
else if (choice == 4)
ShowData();
else
[Link]("Invalid
choice");
[Link]("Continue :
\[Link] \[Link]");
ch = [Link]();
} while (ch == 1);
}catch (Exception e){
[Link]("Please Next time
Enter the yes = 1 , no = 2 !");
}
}
}
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
try {
int ch;
do {
[Link]("1. Insert
Book");
[Link]("2. Update
Book");
[Link]("3. Delete
Book");
[Link]("4. Show
Book");
[Link]("Enter choice :
");
int choice = [Link]();
if (choice == 1)
insertBook();
else if (choice == 2)
updateBook();
else if (choice == 3)
deleteBook();
else if (choice == 4)
ShowData();
else
[Link]("Invalid
choice");
[Link]("Continue :
\[Link] \[Link]");
ch = [Link]();
} while (ch == 1);
}catch (Exception e){
[Link]("Please Next time
Enter the yes = 1 , no = 2 !");
}
}
}