Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

storing date in mysql

 
Jyoti Jadhav
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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();
 
Paul Campbell
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you in auto-commit mode?
 
Jyoti Jadhav
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic