How to fix this code? What should i use instead of integer %d while i'm working with dates?
public static void entryAdd()
{
Scanner scan= new Scanner(System.in);
System.out.print(" Student Number :");
int newNumber= scan.nextInt();
System.out.print(" Entry no :");
int entryNumber=scan.nextInt();
System.out.print(" Borrow Date :");
int borrowDate=scan.nextInt();
System.out.print("Return Date :");
int returnDate=scan.nextInt();
try{
Statement stmt=con.createStatement();
String query=String.format("insert into entry values( %d, %d, %d, %d, %d)", newNumber,entryNumber,borrowDate, returnDate);
int add = stmt.executeUpdate(query);
System.out.println("Entry Added");
}catch(Exception e){ System.out.println(e);}
}
You could use string to instead of date, in MySQL you could insert string date. MySQL will change it to real date.
public static void entryAdd()
{
Scanner scan= new Scanner(System.in);
System.out.print(" Student Number :");
int newNumber= scan.nextInt();
System.out.print(" Entry no :");
int entryNumber=scan.nextInt();
System.out.print(" Borrow Date :");
String borrow=scan.next();
System.out.print("Return Date :");
String return=scan.next();
try{
Statement stmt=con.createStatement();
String query=String.format("insert into entry values( %d, %d, %d, %s, %s)", newNumber,entryNumber,borrow, return);
int add = stmt.executeUpdate(query);
System.out.println("Entry Added");
}catch(Exception e){ System.out.println(e);}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments