Skip to content

Instantly share code, notes, and snippets.

@avinashseth
Last active May 21, 2019 07:01
Show Gist options
  • Save avinashseth/0d51048b900cbcfc9cd31f3ec5687e47 to your computer and use it in GitHub Desktop.
Save avinashseth/0d51048b900cbcfc9cd31f3ec5687e47 to your computer and use it in GitHub Desktop.
package drinking;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;
public class Home {
public static void main(String[] args) {
Scanner getUserInput = new Scanner(System.in);
int userInput = 0;
Dblibrary dbl = new Dblibrary();
do
{
System.out.println("1) To Read the data (SELECT)");
System.out.println("2) To Insert the data (INSERT)");
System.out.println("3) To update the data (UPDATE)");
System.out.println("4) To Delete the data (DELETE)");
System.out.println("0) To exit");
System.out.print("Enter your choice:");
userInput = getUserInput.nextInt();
if(userInput == 1) {
dbl.readTheData();
} else if(userInput == 2){
System.out.print("Enter interns points:");
int points = getUserInput.nextInt();
getUserInput.nextLine();
System.out.print("Enter intern name:");
String name = getUserInput.nextLine();
dbl.createData(name, points);
} else if(userInput == 3) {
System.out.print("Enter intern id:");
int internId = getUserInput.nextInt();
// check if id exists
getUserInput.nextLine();
System.out.print("Enter new name:");
String name = getUserInput.nextLine();
System.out.print("Enter new points:");
int points = getUserInput.nextInt();
if(dbl.updateData(internId, name, points))
{
System.out.println("Intern details udpated");
}
else
{
System.out.println("Unable to udpate intern details");
}
} else if (userInput == 4) {
System.out.print("Enter intern id to be deleted:");
int internId = getUserInput.nextInt();
getUserInput.nextLine();
if(dbl.deleteRow(internId) == 1) {
System.out.println("Intern details removed");
} else {
System.out.println("Something went wrong");
}
} else if(userInput == 0) {
System.out.println("Program existed successfully!");
} else {
System.out.println("Invalid input " + userInput);
}
} while (userInput != 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment