我必须从.csv文件导入发货表中的一些数据,但我在输入日期方面有问题。这是我的发电机:
class Shipment extends Generator
{
private String snd_time;
private String dliv_time;
private int deliv_id;
private int post_id;
int d, m, y, rnd;
public Shipment() throws FileNotFoundException, Exception
{
PrintWriter wr = new PrintWriter("ShipmentData.csv");
for(int i = 1; i < 100001; i++){
m = 1 + r.nextInt(12);
y = 2005 + r.nextInt(16);
if(m == 1 || m == 3 || m ==5 || m ==7 || m ==8 || m ==10 || m ==12)
d = 1+r.nextInt(31);
if(m == 4 || m == 6 || m == 9 || m == 11)
d = 1 + r.nextInt(30);
if((y % 4 == 0) && m == 2)
d = 1 + r.nextInt(29);
if((y % 4 ) != 0 && m == 2 )
d = 1 + r.nextInt(28);
if(m >= 10 && d >= 10)
snd_time = Integer.toString(d) + "/" + Integer.toString(m) + "/" + Integer.toString(y);
if(m < 10 && d < 10)
snd_time = "0" + Integer.toString(d) + "/" + "0" + Integer.toString(m) + "/" + Integer.toString(y);
if(d < 10 && m >= 10)
snd_time = "0" + Integer.toString(d) + "/" + Integer.toString(m) + "/" +Integer.toString(y);
if(m < 10 && d >= 10)
snd_time = Integer.toString(d) + "/" + "0" + Integer.toString(m) + "/" + Integer.toString(y);
rnd = 1 + r.nextInt(7);
if(m == 1 || m == 3 || m ==5 || m ==7 || m ==8 || m ==10 || m ==12)
{
if((d + rnd) > 31 ) {
d = (d + rnd) - 31;
m++;
if(m > 12) {
m = 1;
y++;
}
}
if((d + rnd) < 31)
d += rnd;
}
if(m == 4 || m == 6 || m == 9 || m == 11)
{
if((d + rnd) > 30) {
d = (d + rnd) - 30;
m++;
if(m > 12) {
m = 1;
y++;
}
}
if((d + rnd) < 30)
d += rnd;
}
if((y % 4 == 0) && m == 2)
{
if((d + rnd) > 29) {
d = (d + rnd) - 29;
m++;
if(m > 12) {
m = 1;
y++;
}
}
if((d + rnd) < 29)
d += rnd;
}
if((y % 4 ) != 0 && m == 2 )
{
if((d + rnd) > 28) {
d = (d + rnd) - 28;
m++;
if(m > 12) {
m = 1;
y++;
}
}
if((d + rnd) < 28)
d += rnd;
}
if(m >= 10 && d >= 10)
dliv_time = Integer.toString(d) + "/" + Integer.toString(m) + "/" + Integer.toString(y);
if(m < 10 && d < 10)
dliv_time = "0" + Integer.toString(d) + "/" /*+ "0"*/ + Integer.toString(m) + "/" + Integer.toString(y);
if(d < 10 && m >= 10)
dliv_time = "0" + Integer.toString(d) + "/" + Integer.toString(m) + "/" +Integer.toString(y);
if(m < 10 && d >= 10)
dliv_time = Integer.toString(d) + "/" + "0" + Integer.toString(m) + "/" + Integer.toString(y);
deliv_id = 1 + r.nextInt(100000);
post_id = 1 + r.nextInt(100000);
wr.println(i + "," + this.snd_time + "," + this.dliv_time + "," + this.deliv_id + "," + this.post_id );
}
wr.close();
}
}
这是我的ctl文件:
LOAD DATA
INFILE 'D:\databaseProject\Data\ShipmentData.csv'
INSERT INTO TABLE shipment
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
id,
send_time,
deliv_time DATE "dd/mm/yyyy",
delivery_id DATE "dd/mm/yyyy",
post_id
)
但是当我加载这个ctl文件时,我得到了这个错误
记录4:已拒绝-表装运错误,列发送时间。ora-01843:不是有效月份
我试着在没有0的情况下写我的日期,但仍然不起作用,我找不到解决问题的方法
暂无答案!
目前还没有任何答案,快来回答吧!