How to getdate java

alongova :

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);}

    }
marqueen :

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.

edited at
0

Comments

0 comments
Login to comment

Related

Java Date getDate() deprecated, refactored to use calendar but looks ugly

How to calculate age (in years) based on Date of Birth and getDate()

Java getDate 0000/00/00 return strange value

In SSIS expression how can we store only date from getdate()

how to convert GETDATE() in a SQL database for a specific format while creating table?

How to fix deprecated .getDate()

calculate how to get GETDATE() -4 using customer function in SQL

How can getdate["weekday"] start from Monday instead of sunday?

How to convert SQL Server 2016 GETDATE() function output to MMM dd, yyyy?

How to create a function in SQL Server to compare 2 datetime2 values with GETDate and return a boolean

How to make the GETDATE dynamic so that if reports run on any date it should show the information of the specified date

How can I generate a random timestamp appended to getdate() in SQL Server?

How to convert GetDate() in 1 Jan 2014 format?

How to compare various date formats stored as nvarchar in a column with the getdate() in SQL Server

How to replace getDate() from the type Date which is deprecated?

getdate() function

How to get different times in the same query session using getdate()?

JavaScript - Weird usage of Date.getDate() for to get the days-count of a month. How does that work?

how to insert getdate function using vba

how to compare date with GETDATE() in sql server 2008

How can I Insert each row With getdate() + 20 second

GetDate Function

SQL: How to get an Integar value of the previous month in the format YYYYMM based on the GETDATE() Function

SSIS 2016 How to Pass UNC Path plus GETDATE() to ConnectionString Property of Flat File Connection Manager?

How to resolve error with SQL Scalar variable using GETDATE

How to exclude a day of the week with getDate in JavaScript?

How to select data using getdate() + time?

SQL Server How can we write a sql function which returns the records where getdate() is between FromDate and Todate

how to filter an array using getDate()?