java - Changing date format and storing it in a variable in mysql -
import java.sql.connection; import java.sql.date; import java.sql.drivermanager; import java.sql.preparedstatement; import java.sql.resultset; import java.sql.statement; import java.util.*; public class sql_type4 { public static void main(string args[]){ date fun; date fun2; try{ class.forname("com.mysql.jdbc.driver"); connection con=drivermanager.getconnection( "jdbc:mysql://localhost:3306/mca2b","root","siddheshkk"); statement stmt=con.createstatement(); resultset result=stmt.executequery("select id,name, date_format(from_unixtime(dateee),'%d/%m/%y') datee empwhere dateee >= curdate()"); while(result.next()) { fun=result.getdate("datee"); system.out.println(fun); } con.close(); } catch(exception e) { system.out.println(e); } } }
here want change format of date , store result in 1 variable . how can ? above code gives error bad format date '22/08/1970' in column 3. please help. alot in advance :)
you're trying use jdbc getdate() method retrieve text string. that's because converted standard mysql date data type string in query date_format(). resulting value doesn't date, jdbc gacks on it. should use getstring() instead. or, maybe should conversion desired date format in java code rather in mysql.
Comments
Post a Comment