I have crated a menu in java but I need help inserting records in to a database
ID: 3544200 • Letter: I
Question
I have crated a menu in java but I need help inserting records in to a database and deleating a record and searching the database.
The following is the menu:
import java.util.Scanner;
public class Assignment1 {
public Assignment1() {
}
public static void main(String[] args) {
Scanner choose = new Scanner(System.in);
String choice = null;
while (!"end".equals(choice)) {
System.out.println("Welcome to the database menu! ");
System.out.println("Press 1 to insert a new record");
System.out.println("Press 2 to delete a record");
System.out.println("Press 3 to search the database (by last name)");
System.out.println("Press 4to quit");
choice = choose.nextLine();
if ("1".equals(choice)) {
System.out.println("You choose option 1");
choice = null;
}
if ("2".equals(choice)) {
System.out.println("You choose option 2");
choice = null;
}
if ("3".equals(choice)) {
System.out.println("You choose option 3");
choice = null;
}
if ("4".equals(choice)) {
System.out.println("Good bye!");
choice = null;
exit();
}
choose.close();
}
private static void exit() {
System.exit(0);
}
}
Explanation / Answer
You need to use JDBC queries for that, import sql jar, create a connection object and initialize with your database connection, define driver, and then use JDBC queries, like "insert into 'table name'" or " delete from 'tablename'"
Actually you need to learn JDBC to successfully implement your task. If you want any source to learn about it comment here and rate my answer, i will give you a ebook.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.