3
Well I need to do a String to Calendar conversion and I have to set the value in a variable (that is in type Calendar) in a class and then insert the data in a database!
System.out.println("Digite a Data de Aniversario do Funcionario");
String data = scan1.nextLine();
SimpleDateFormat form = new SimpleDateFormat("yyyy/MM/dd");
Date data1 =(Date)form.parse(data);
Calendar cal = Calendar.getInstance();
cal.setTime(data1);
f.setDataAniver(cal.setTime(data1));
What’s the doubt? The code you presented is already converting to Calendar. Click on [Edit] and detail what’s the doubt you have.
– user28595
the problem is that when entering into the database it does not insert correctly! gets the data incorrectly
– Wander Lopes
So you want to convert Calendar back to date?
– user28595
Wander, welcome to [en.so]! As already stated, the code presented in the question already does what the question asks.I imagine that you created this question assuming that the problem was in this passage, but this assumption was wrong. I suggest you create another question and this time put the problem that is really happening and the snippet of code where it occurs. Hug.
– utluiz
JDBC, standard database access API with Java does not accept Calendar, only
java.sql.Date
orjava.sql.Timestamp
. Anyway, you need to tell what technology you are using and post the snippet where you insert the data into the database, because as I said, the problem is not the conversion from string to calendar.– utluiz
@utluiz Thanks for the info! I am using Hibernate! I managed to solve my problem, it was a lack of attention from me with the code presented.
– Wander Lopes