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
10 ответов
+ 3
I recommend you to use following statements to retrieve date column,
Date date = resultset.getDate("");
+ 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.*;
+ 1
Use drivermanager class to get connection
+ 1
Please try,
Date date = resultset.getDate("");
+ 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
+ 1
Avinesh thank you a lot for this code. :)
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.
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)
0
Hi Avinesh no until now not.
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.🙈