8:21 am - Sunday October 21, 2018

Statement DATE_ADD Example program in java Jdbc mysql database

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

Create Table and  Insert values:


Mysql>
 create table Student(name varchar(10),course varchar(5),Attendance float(5));
       Insert into Student(Arun,cse,93.45);
      Insert into Student(Karthick,cse,67.78);
        Insert into Student(Tamil,cse,87.89);

   Jdbc code:

package myjava1;

import java.sql.*;

public class Dateadd{

 /**
 * @param args
 */

 // TODO Auto-generated method stub

 public static void main(String[] args) throws Exception {

 Class.forName("com.mysql.jdbc.Driver").newInstance();
 Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/Arun","root","root");
 Statement st = conn.createStatement();

 st = conn.createStatement();
 ResultSet rs = st.executeQuery(" Select DATE_ADD(NOW(),INTERVAL 12 DAY)from Student");

 while (rs.next()) {
 String name = rs.getString(1);

 System.out.println(name);

 }

 rs.close();
 st.close();
 conn.close();

 }

 }

Output:

Filed in: Z-A All Java Codes

Comments are closed.