2:21 am - Friday April 19, 2019

Statement DATE_SUB 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);

Java Code:

package myjava1;

import java.sql.*;

public class Datesub{

	/**
	 * @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_SUB(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.