8:02 pm - Wednesday November 26, 2014

Statement CURDATETIME() Example program in java Jdbc mysql database

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 Date{

	/**
	 * @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_FORMAT(NOW(),'%b %d %Y %h:%i %p') AS XXXX 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.