Conversion of data type from MySql to JSP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jith87
    New Member
    • Jul 2007
    • 58

    Conversion of data type from MySql to JSP

    My proj involves JSP @ front end n MySql @ back end and connectivity is established thru JDBC. The thing is when i store values from the front end into the db i need to change the data types n vice versa.Consider ths.

    I m retrieving date from the db thru the result set i m traversing thru each n every record(next() function is used).

    String d1 = rs.getString(2) ;System.out.pri ntln("Date="+da te);

    How do i convert the date field into a java.sq.Date value such dat it can be retrieved back @ front end? If i directly the variable d1(mentioned above) as java.sql.Date then there is arises compatibility error....

    Help me pls..........
  • madhoriya22
    Contributor
    • Jul 2007
    • 251

    #2
    Originally posted by jith87
    My proj involves JSP @ front end n MySql @ back end and connectivity is established thru JDBC. The thing is when i store values from the front end into the db i need to change the data types n vice versa.Consider ths.

    I m retrieving date from the db thru the result set i m traversing thru each n every record(next() function is used).

    String d1 = rs.getString(2) ;System.out.pri ntln("Date="+da te);

    How do i convert the date field into a java.sq.Date value such dat it can be retrieved back @ front end? If i directly the variable d1(mentioned above) as java.sql.Date then there is arises compatibility error....

    Help me pls..........
    Hi,
    Can u make urself more clear? when do you want to convert the date :
    1. while sending date from jsp to mysql or
    2. while getting date from db and sending it to jsp.

    Comment

    • jith87
      New Member
      • Jul 2007
      • 58

      #3
      Originally posted by madhoriya22
      Hi,
      Can u make urself more clear? when do you want to convert the date :
      1. while sending date from jsp to mysql or
      2. while getting date from db and sending it to jsp.

      while getting date from db and sending it to jsp

      Comment

      • madhoriya22
        Contributor
        • Jul 2007
        • 251

        #4
        Originally posted by jith87
        while getting date from db and sending it to jsp
        Hi,
        then db itself retunrs date in sql format, isn't it ?

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by jith87
          My proj involves JSP @ front end n MySql @ back end and connectivity is established thru JDBC. The thing is when i store values from the front end into the db i need to change the data types n vice versa.Consider ths.

          I m retrieving date from the db thru the result set i m traversing thru each n every record(next() function is used).

          String d1 = rs.getString(2) ;System.out.pri ntln("Date="+da te);

          How do i convert the date field into a java.sq.Date value such dat it can be retrieved back @ front end? If i directly the variable d1(mentioned above) as java.sql.Date then there is arises compatibility error....

          Help me pls..........
          Have a look at this Code.

          [code=java]
          Calendar c = new GregorianCalend ar();
          c.setTime(rs.ge tDate(2));
          int day = c.get(Calendar. DATE);
          int month = c.get(Calendar. MONTH);
          int year = c.get(Calendar. YEAR);
          String date_str = ""+day+"/"+month+"/"+year;
          [/code]

          Are you looking for this?
          Then go and enjoy with this code.
          Good Luck!

          Kind regards,
          Dmjpro.

          Comment

          • jith87
            New Member
            • Jul 2007
            • 58

            #6
            Originally posted by madhoriya22
            Hi,
            then db itself retunrs date in sql format, isn't it ?

            Yes bt i wanna convert the sql format date to java compatible date format. Wht to do for that?

            Comment

            • dmjpro
              Top Contributor
              • Jan 2007
              • 2476

              #7
              Originally posted by jith87
              Yes bt i wanna convert the sql format date to java compatible date format. Wht to do for that?
              Have a look at my Code.
              Then you will understand by yourself.

              Kind regards,
              Dmjpro.

              Comment

              • jith87
                New Member
                • Jul 2007
                • 58

                #8
                Originally posted by dmjpro
                Have a look at my Code.
                Then you will understand by yourself.

                Kind regards,
                Dmjpro.

                date_rs_test.ja va:36: cannot find symbol
                symbol : variable Calendar

                ths s the error dat i got....

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Originally posted by jith87
                  date_rs_test.ja va:36: cannot find symbol
                  symbol : variable Calendar

                  ths s the error dat i got....
                  Open the API docs for ResultSet and you will see that there is a getDate method.

                  Comment

                  • dmjpro
                    Top Contributor
                    • Jan 2007
                    • 2476

                    #10
                    Originally posted by jith87
                    date_rs_test.ja va:36: cannot find symbol
                    symbol : variable Calendar

                    ths s the error dat i got....
                    [code=java]
                    import java.util.*;
                    [/code]

                    Kind regards,
                    Dmjpro.

                    Comment

                    Working...