0

MySQL table export with column names and a date column. How can I solve this?

So far I have managed a CSV export with 5 columns, time, customer, employee, service and description. But I'm not sure is this the right code for the time export. while(rs.next()) { sb.append(rs.getDate("date")); sb.append(";"); sb.append(rs.getTime("time")); sb.append(";"); I tried this code to export the date column, but it doesn't work. I hope you can help me. Thank you. BR Olivia https://code.sololearn.com/cAXM4GW7SFTQ/?ref=app

26th Jan 2020, 6:33 PM
Vivi
Vivi - avatar
10 odpowiedzi
+ 3
I recommend you to use following statements to retrieve date column, Date date = resultset.getDate("");
26th Jan 2020, 6:59 PM
Akshay Harshora
Akshay Harshora - avatar
+ 2
while(rs.next()) { Date date = rs.getDate("datum"); sb.append(date); sb.append(";"); sb.append(rs.getTime("zeit")); sb.append(";"); sb.append(rs.getString("kunde")); sb.append(";"); sb.append(rs.getString("dienstleistung")); sb.append(";"); sb.append(rs.getString("beschreibung")); sb.append(";"); sb.append(rs.getString("mitarbeiter")); sb.append("\r\n"); } For date class we have to include import java.util.*;
26th Jan 2020, 8:03 PM
Akshay Harshora
Akshay Harshora - avatar
+ 1
Use drivermanager class to get connection
26th Jan 2020, 7:15 PM
Akshay Harshora
Akshay Harshora - avatar
+ 1
Please try, Date date = resultset.getDate("");
26th Jan 2020, 7:33 PM
Akshay Harshora
Akshay Harshora - avatar
+ 1
Did you learn the time API? Here is a simple example to help you get going with your task. https://code.sololearn.com/cMdQw5y7VJUE/?ref=app
26th Jan 2020, 7:41 PM
Avinesh
Avinesh - avatar
+ 1
Avinesh thank you a lot for this code. :)
26th Jan 2020, 7:58 PM
Vivi
Vivi - avatar
0
Hi akshay harshora, thank you for your help. :) The connection it works, only the column names and the date column it doesn't work.
26th Jan 2020, 7:32 PM
Vivi
Vivi - avatar
0
akshay harshora I tried it at this position: while(rs.next()) { Date date = rs.getDate(""); .... but I received an error like: Date cannot be solved to a type. Which Import I have to do? Import 'Date' (sun.util.calendar.BaseCalendar) or (sun.util.calendar.LocalGregorianCalendar) or (java.util) or (java.sql)
26th Jan 2020, 7:53 PM
Vivi
Vivi - avatar
0
Hi Avinesh no until now not.
26th Jan 2020, 7:54 PM
Vivi
Vivi - avatar
0
many thanks akshay harshora :), now I don't have errors, but the csv file is empty. The csv file it works, without the date codes.🙈
26th Jan 2020, 8:09 PM
Vivi
Vivi - avatar