NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class UpdateTable {

public static void main(String[] args) throws SQLException {
try {
Scanner scan = new Scanner(System.in);
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/Emp", "root", "");
Statement st = con.createStatement();
while(true) {
System.out.println("Choose which action you want to perform: n 1: For Add Employee n"
+ "2: For Show Employee n 3: For Edit Employee n 4: For Delete Empployee n 5: For Search Employee n 6: For Logout");
int adminc = scan.nextInt();
if(adminc==1) {
System.out.print("Enter Employee ID: ");
String eid = scan.next();
System.out.print("Enter Employee Name: ");
String ename = scan.next();
System.out.print("Enter Employee Mobile No.: ");
String emobile = scan.next();
System.out.print("Enter Employee Age: ");
int eage = scan.nextInt();
String dl = "Select E_id from Employee where E_id="+"'"+eid+"'";
String d1 = "Select E_mobile from Employee where E_mobile="+"'"+emobile+"'";
ResultSet rs1 = st.executeQuery(dl);
ResultSet rs2 = st.executeQuery(d1);
if(emobile.length()==10) {
if(eage>18 && eage<32) {
if(rs1.next()) {
System.out.println("Duplicate Librarian");
}else if(rs2.next()){
System.out.println("Duplicate Mobile Number");
}else{
String eadd = "Insert into Employee values("+"'"+eid+"'"+","+"'"+ename+"'"+","+"'"+emobile+"'"+","+eage+")";
st.execute(eadd);
System.out.println("New Employee Added Successfully");
}
}else {
System.out.println("Invalid Age Enter Between 18 - 32");
}
}
else {
System.out.println("Invalid Mobile Number");
}
}else if(adminc==2) {
System.out.println("Showing Employees............");
String eshow = "Select * from Employee";
ResultSet rs2 = st.executeQuery(eshow);
while(rs2.next()) {
System.out.println(rs2.getString("E_id")+" "+rs2.getString("E_name")+" "+rs2.getString("E_mobile")+" "+rs2.getInt("E_age"));
}
}else if(adminc==3) {
System.out.print("Enter Employee ID: ");
String eid = scan.next();
System.out.print("Enter Employee Name if you want to edit otherwise write same name: ");
String ename = scan.next();
System.out.print("Enter Employee Mobile No. if you want to edit otherwise write same mobile: ");
String emobile = scan.next();
System.out.print("Enter Employee Age if you want to edit otherwise write same age: ");
int eage = scan.nextInt();
String d1 = "Select Mobile_no from Librarian where E_mobile="+"'"+emobile+"'";
ResultSet rs2 = st.executeQuery(d1);
if(emobile.length()==10) {
if(eage>18 && eage<32) {
if(rs2.next()){
System.out.println("Duplicate Mobile Number");
}else{
String eup = "UPDATE Employee SET E_name="+"'"+ename+"'"+","+"E_mobile="+"'"+emobile+"'"+","+"E_age="+eage+"WHERE E_id = "+eid;
st.execute(eup);
System.out.println("Employee's Data Updated Successfully");
}
}else {
System.out.println("Invalid Age Enter Between 18 - 32");
}
}
else {
System.out.println("Invalid Mobile Number");
}
}else if(adminc==4) {
System.out.print("Enter Employee ID: ");
String lid = scan.next();
String dl = "Delete from Employee where L_id="+"'"+lid+"'";
st.execute(dl);
System.out.println("Employee Deleted Successfully");
}else if(adminc==5){
System.out.print("Enter Librarian ID: ");
String eid = scan.next();
System.out.println("Searchng Librarian............");
String eshow = "Select * from Employee where E_id="+"'"+eid+"'";
ResultSet rs2 = st.executeQuery(eshow);
if(rs2.next()) {
System.out.println(rs2.getString("E_id")+" "+rs2.getString("E_name")+" "+rs2.getString("E_mobile")+" "+rs2.getInt("E_age"));
}else {
System.out.println("No Employee Found");
}
}else if(adminc==6) {
System.out.println("Log Out......");
break;
}else {
System.out.println("Wrong Choice! Choose within given number");
}
}
scan.close();
}catch(Exception e) {
System.out.println("Some error: " + e);
}
}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.