How do I get current date details in java? I have developed a class:
public class RetailerWs {
public String customerData(){
String customerInfo = "";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pro","root","");
//Find customer information where the customer ID is maximum
PreparedStatement statement = con.prepareStatement("select * from orders where status='Q' AND date='2012-08-01'");
ResultSet result = statement.executeQuery();
int count=0;
count++;
// System.out.println(count);
while(result.next()){
System.out.println(count);
}
}
catch(Exception exc){
System.out.println(exc.getMessage());
}
return customerInfo;
}
}
This is another class.
public class Demo {
public static void main(String[] args){
RetailerWs obj = new RetailerWs();
System.out.println(obj.customerData());
}
}
if I run demo
, it calls RetailerWs
after that it displays the value of count
. The problem is the currently I insert the date manually, i.e.
PreparedStatement statement = con.prepareStatement("select * from orders where status='Q' AND date='2012-08-01'");
But I want a query that fetches the current date. How can I create and call it? Please help me.