Reputation: 75
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());
Upvotes: 0
Views: 406
Reputation: 3660
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());
}
Upvotes: 0