• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

storing date in mysql

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
in my program i am entering a string parsing it to date and storing it in table.
i am not getting any error but the table is not upfdating..
code is...

con2=GetConnection();
PreparedStatement st=con2.prepareStatement("INSERT INTO employee VALUES(?,?,?,?,?,?)");

String s="12/03/2007";
SimpleDateFormat df=new SimpleDateFormat("mm/dd/yyyy");
java.util.Date p=df.parse(s);
st.setString(1,"7");
st.setString(2,"manasi");
st.setString(3,"tilak");
st.setDate(4,(Date) p);
st.setString(5,"400000");
st.setString(6,"n");

st.executeUpdate();
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
are you in auto-commit mode?
 
Jyoti Jadhav
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Campbell:
are you in auto-commit mode?



how to check the auto commit mode?and i should or should not in auto commit mode..

thanks
 
Jyoti Jadhav
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Campbell:
are you in auto-commit mode?



yes i am in autocommit mode because executing
select @@autocommit;
giving me value 1.
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure you are not getting a ClassCastException?

Here, you are casting a java.util.Date object as java.sql.Date. The object isn't an instance of java.sql.Date however.

To create a java.sql.Date from a java.util.Date you have to do the following:

The same goes for Time and Timestamp.
 
Jyoti Jadhav
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rob Prime:
Are you sure you are not getting a ClassCastException?

Here, you are casting a java.util.Date object as java.sql.Date. The object isn't an instance of java.sql.Date however.

To create a java.sql.Date from a java.util.Date you have to do the following:

The same goes for Time and Timestamp.




thanks
it worked.
reply
    Bookmark Topic Watch Topic
  • New Topic