0

I need to add current date +7 day in to my sql database and retrieve it back how do i do that?

Calendar cal = Calendar.getInstance();
                        cal.add(Calendar.DATE, 7); // add 7 days  
                        int date = cal.get(Calendar.DATE);
                        int month = cal.get(Calendar.MONTH);
                        int year = cal.get(Calendar.YEAR);
                        String newdate = Integer.toString(date);
                        String concat = newdate.concat("-" + Integer.toString(cal.get(Calendar.MONTH)) + "-" + Integer.toString(cal.get(Calendar.YEAR)));

I found this code

java.util.Date newDate = new Date(result.getDate("VALUEDATE").getTime());
1

2 Answers 2

1

You can do that in MySQL directly

update your_table
set date_column = date_column + interval 7 day

Doc

Sign up to request clarification or add additional context in comments.

Comments

0

Download the Java MySql Connector library http://dev.mysql.com/downloads/connector/j/ and add the jar file to the build path.

Now you can add to your table

    Connection conn = null;
    try {
        conn =  DriverManager.getConnection("<databaseURLHere>" + "user=<usernameHere>&password=<passwordHere");
        Statement stmt = conn.createStatement();
        String uid = UUID.randomUUID().toString();
        uid = uid.replaceAll("-", "");
        uid = uid.substring(0, 16);
        if (stmt.execute("<sql query here>")) {
        //    rs = stmt.getResultSet();
        }

    } catch (SQLException ex) {
        System.out.println("SQLException: " + ex.getMessage());
        System.out.println("SQLState: " + ex.getSQLState());
        System.out.println("VendorError: " + ex.getErrorCode());
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.