So your variable declarations become: //get the info We need a LocalDate and a DateTimeFormatter. Instead rely on java.time, the modern Java date and time API. All those classes are poorly designed, the last two particularly troublesome. It’s time someone writes the modern answer to this question.Īssuming that you are using (or can start using) a JDBC 4.2 compliant driver you should not use the two Date classes nor DateFormat or SimpleDateFormat. ("\nAppointment added!\n") Ĭonn.close() //finished with the database PreparedStatement stat = conn.prepareStatement( PreparedStatement max = conn.prepareStatement("SELECT MAX(ID) FROM Calendar") public static void addAppointment() throws SQLExceptionĬonnection conn = SimpleDataSource.getConnection() //connect to the database I've added to it and mucked about with it a bunch trying to get it to work, but it's still giving me this:Įxception in thread "main" : cannot be cast to Īny ideas on what I'm doing wrong or how to make this work would be very much appreciated.Įdit: I thought perhaps it would help if I added the bit of code that is calling this so maybe it will be more clear how I am trying to use it, so here is the addAppointment() method, so you can see where getDay() is being called and where it's going. ("Please enter a valid date! Format is yyyy/mm/dd") ("\nPlease enter the date of the appointment, format: yyyy/mm/dd") Here is the bit where I'm getting the error: private static getDay()ĭateFormat df = new SimpleDateFormat("yyyy/MM/dd") ![]() It has to take input from the user to add or cancel appointments, so as far as I know that means I need to convert a string to a date.Īs you can see, no there. I'm supposed to be making a program that stores what amounts to a list of appointments in a database, with a description, date, start time, and end time. I've spent hours looking around and trying to figure this out.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |