-4

Possible Duplicate:
converting timestamp to date in java

This is my database:

  • Date status

  • 1343993311 Q

  • 1343892452 C
  • 1343892477 P

Here I have to check the query current date+status=Q information and get the count value.

This is my code:

public class TodayQ {
 public int data(){
int count=0;

//count++;

try{
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pro","root","");

    PreparedStatement statement =  con.prepareStatement("select * from orders where status='Q' AND date=CURDATE()");
     ResultSet result = statement.executeQuery();
     while(result.next()) {
            // Do something with the row returned.
            count++; //if the first col is a count.
        }



     }

      catch(Exception exc){
      System.out.println(exc.getMessage());
      }


    return count;
       }

        }

dis is my other class:

    public class Demo {
    public static void main(String[] args) throws ParseException{
    TodayQ obj = new TodayQ();
    System.out.println(obj.data());

     }

     }

Here I have to edit the date is (yyyy-mm-dd) format.Now I got the output.but I wish to use timestamp on my database.so how is converted timestamp to date in java.How is use that code in my code.please help me.How is to do????

Community
  • 1
  • 1
  • 2
    I wonder where this 'Order assignment' takes place? Related questions are [here](http://stackoverflow.com/questions/11789551/sum-of-total-in-java#comment15664080_11789551) and [here](http://stackoverflow.com/questions/11790158/get-sumtotal-in-java-from-mysql-database#comment15663822_11790158). The whole class seems to be active on SO?! – home Aug 04 '12 at 06:03
  • 1
    Could it possibly be an assignment?? – MadProgrammer Aug 04 '12 at 06:17

1 Answers1

0

You should try the following thing in your code

DateFormat format = new SimpleDateFormat("yyyy-mm-dd");
Date date = format.parse("1343993311");

Here date object will have java.util.Date objects reference. Means timestamp is converted into Date object.

Bhavik Ambani
  • 6,557
  • 14
  • 55
  • 86
  • i have to add above line after int count=0.that time i got following exceptions:Exception in thread "main" java.text.ParseException: Unparseable date: "1343455049" at java.text.DateFormat.parse(DateFormat.java:337) at com.xcart.TodayQ.data(TodayQ.java:16) at com.xcart.Demo.main(Demo.java:8) – user1570318 Aug 04 '12 at 06:25