Import data into sql developer from .csv file - sql

I have to import some data in my Shipment table from .csv file,but i have problem with imorting DATE.
Here is you can see my generator:
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();
}
}
Here is my ctl file:
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
)
but when i load this ctl file i get this error
Record 4: Rejected - Error on table SHIPMENT, column SEND_TIME.
ORA-01843: not a valid month
I've tried to write my date without 0, but it still doesn't work and i cannot find a solution for my problem

Related

Get Years months days hours minutes from moment from duration

const seconds = 1000000
var now = moment(moment.duration(seconds).asSeconds()).format('Y[y],M[m],D[d],H[h]')
I want to format this seconds to years, months, days,hours,minutes so I am not able to get where I am making mistake how can I get this format in React native
this code might help you
export function formatDate(seconds) {
var d = new Date(seconds*1000),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [day,month,year].join('/');
}
this code will return you dd/mm/yyyy. if you want to return date+time then you simply return
export function formatDate(seconds) {
var d = new Date(seconds*1000)
return d.toLocaleString()
}
if you want to get remains time, day, month and year then you should use this code
function secondsToHms(sec) {
sec = Number(sec);
var y = Math.floor(sec/31536000) //<<years
var w= Math.floor(y*31536000)
var w1=Math.floor(w-sec)
w=Math.floor(Math.abs(w1)/604800)//<<weeks
var d=Math.floor(Math.abs(w)*604800)
var d1=Math.floor(Math.abs(d)-Math.abs(w1))
d=Math.floor(Math.abs(d1)/86400)
d=Math.abs(d) //<<day
var h = Math.floor(d*86400);
h=Math.floor(h-Math.abs(d1))
h=Math.floor(Math.abs(h)/3600)//<<hours
var m = Math.floor(sec % 3600 / 60);//<<minutes
var s = Math.floor(sec % 3600 % 60);//<<seconds
var yDisplay = y > 0 ? y + (y == 1 ? " year, " : " years, ") : "0 year, ";
var wDisplay = w > 0 ? w + (w == 1 ? " week, " : " weeks, ") : "0 week, ";
var dDisplay = d > 0 ? d + (d == 1 ? " day, " : " days, ") : "0 day, ";
var hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, ") : "0 hour, ";
var mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes, ") : "0 minute, ";
var sDisplay = s > 0 ? s + (s == 1 ? " second. " : " seconds. ") : "0 second. ";
return yDisplay + wDisplay + dDisplay + hDisplay + mDisplay + sDisplay;
}
console.log(secondsToHms(1000000))

Rounding Non-LinearExpr with google or-tools SAT solver

Using CP-SAT of google or-tools I'm trying to write this constraint:
q >= (50x + 100y + 150z + 200k + 250p + 300v) / (x + y + z + k + p + v)
Where q is a simple integer.
The thing is I need to round the right side of the equation (let's call it expression) as follows:
if(expression < 75) {
expression = 50;
} else if(expression < 125) {
expression = 100;
} else if(expression < 175) {
expression = 150;
} else if(expression < 225) {
expression = 200;
} else if(expression < 275) {
expression = 250;
} else {
expression = 300;
}
So I need to round the expression
(50x + 100y + 150z + 200k + 250p + 300v) / (x + y + z + k + p + v)
So that it gets one of the following values:
{50, 100, 150, 200, 250, 300}
Let's review 2 cases:
Case 1
q = 180 and expression = 176.
Although the condition 180 >= 176 is true, after rounding up 176 to 200 the tested condition should be 180 >= 200 which is false.
So for q = 180 and expression = 176 I would like the condition to return false.
Case 2
q = 210 and expression = 218.
Although the condition 210 >= 218 is false, after rounding down 218 to 200 the tested condition should be 210 >= 200 which is true.
So for q = 210 and expression = 218 I would like the condition to return true.
I got a great answer here for resolving this challenge over a linear expression but now I need to resolve it for a non-linear expression.
Any suggestions?
Let's rephrase
you have an integer variable e with a value between 0 and 300.
You want to round it to the nearest multiple of 50
if you do:
(e div 50) * 50
you will get the max multiple of 50 less or equal to e
(70 / 50) * 50 -> 50
(99 / 50) * 50 -> 50
(102 / 50) * 50 -> 100
To get a round to nearest, you need to add 25 to e before the division
((e + 25) div 50) * 50
Which will do the correct rounding
((70 + 25) / 50) * 50 -> 50
((99 + 25) / 50) * 50 -> 100
((102 + 25) / 50) * 50 -> 100
with the correct or-tools CP-SAT python code:
numerator = model.NewIntVar(...)
model.Add(numerator == 50x + 100y + 150z + 200k + 250p + 300v)
denom = model.NewIntVar(...)
model.Add(denom == 50x + 100y + 150z + 200k + 250p + 300v)
e = model.NewIntVar(0, 300, 'e')
model.AddDivisionEquality(e, numerator, denom)
shifted_e = model.NewIntVar(25, 325, 'shifted_e')
model.Add(shifted_e == e + 25)
multiple_of_fifty = model.NewIntVar(0, 6, 'multiple_of_fifty')
model.AddDivisionEquality(multiple_of_fifty, shifted_e, 50)
result = model.NewIntVar(0, 300, 'result')
model.Add(result = multiple_of_fifty * 50)
if a and b are positive then
a div b >= q
is equivalent to
a >= q * b
now, your example does not specify how to round (nearest or down)
if you want to round down
q * (x + y + z + k + p + v) <= (50x + 100y + 150z + 200k + 250p + 300v)
If you want to round to nearest, you need to add q / 2 in the right place
q * (x + y + z + k + p + v) <= (50x + 100y + 150z + 200k + 250p + 300v + q / 2)
Now, if you want the other direction
a div b <= q
is equivalent to
a <= q * b + q - 1
The rest of the transformation is the same.

Fingerprint Hardware ID GetHexString

I found a fingerprint class in C# here
I'm trying to convert the function below to VB .NET but I am having issues with the line that reads s+ = (char)....Any help would be appreciated.
private static string GetHexString(byte[] bt)
{
string s = string.Empty;
for (int i = 0; i < bt.Length; i++)
{
byte b = bt[i];
int n, n1, n2;
n = (int)b;
n1 = n & 15;
n2 = (n >> 4) & 15;
if (n2 > 9)
s += ((char)(n2 - 10 + (int)'A')).ToString();
else
s += n2.ToString();
if (n1 > 9)
s += ((char)(n1 - 10 + (int)'A')).ToString();
else
s += n1.ToString();
if ((i + 1) != bt.Length && (i + 1) % 2 == 0) s += "-";
}
return s;
}
Is there a better way to write this function in VB.NET?
This
s += ((char)(n1 - 10 + (int)'A')).ToString();
is the same as
s &= Chr((n1 - 10 + Asc("A")))

Clear Previous selection of Dropdown in EXCEL usingApache POI

I have developed the excel using the Apache NPOI dll using HSSFWORKBOOK. But in my excel having 3 dependent dropdowns one in each other.
Here my question is I am unable to clear the cell value of dependent dropdowns. Let say like dropdown1 have country values and on the selection of this dropdown2 state values got a filter and selected one of the state. Now if I changed the country again able to filter the data but whatever the previous state selection not getting cleared.
code ref:
No, i am just referring the list of columns data from sheet2 to sheet1 using the formulae. below is code ref:
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
//if (i >= MaxRowCount)
//{
// sheet2.CreateRow(1000 + i).CreateCell(1).SetCellValue(ds.Tables[0].Rows[i][1].ToString());
// MaxRowCount += 1;
//}
//else
// sheet2.GetRow(1000 + i).CreateCell(1).SetCellValue(ds.Tables[0].Rows[i][1].ToString());
if (CategoryCount == 250)
{
rownumber = rownumber + 3000;
CategoryCount = 16;
MaxRowCount = 0;
}
DataRow[] DR = ds.Tables[1].Select("LOCATION_ID=" + ds.Tables[0].Rows[i][0].ToString());
int RowCount = 0;
//int rownumber = 1000;
foreach (DataRow d in DR)
{
if (RowCount >= MaxRowCount)
{
sheet2.CreateRow(rownumber + RowCount).CreateCell(CategoryCount).SetCellValue(d[0].ToString());
MaxRowCount += 1;
}
else
{
sheet2.GetRow(rownumber + RowCount).CreateCell(CategoryCount).SetCellValue(d[0].ToString());
}
RowCount++;
}
IName DeptHierarchy_Dept = hssfworkbook.CreateName();
DeptHierarchy_Dept.NameName = "XDeptHierarchy_Dept_SUB" + (XDeptHierarchy_Dept_SUBCount).ToString();
if (CategoryCount / 26 < 1)
DeptHierarchy_Dept.RefersToFormula = "'Template Field Specs2'!$" + ((char)(65 + CategoryCount)).ToString() + "$" + (StartRowNumber + 1) + ":$" + ((char)(65 + CategoryCount)).ToString() + "$" + ((StartRowNumber + 1) + (RowCount == 0 ? 0 : RowCount - 1)).ToString();
else
DeptHierarchy_Dept.RefersToFormula = "'Template Field Specs2'!$" + ((char)(65 + (CategoryCount / 26) - 1)).ToString() + ((char)(65 + CategoryCount % 26)).ToString() + "$" + (StartRowNumber + 1) + ":$" + ((char)(65 + (CategoryCount / 26) - 1)).ToString() + ((char)(65 + CategoryCount % 26)).ToString() + "$" + ((StartRowNumber + 1) + (RowCount == 0 ? 0 : RowCount - 1)).ToString();
CategoryCount++;
XDeptHierarchy_Dept_SUBCount++;
You are looking for "Dependent Drop Down Lists". You'll have to be creative for your formula because your row will keep changing.
one approach i can think of is store the list of "Country-capital" on named region some where deep in excel. On selection of country, parse and find the capital from named region and populate your target cell.
Please see the documentation.
Also this link;

condition is satisfied but it doesn't run the codes

If (need_1a.Text <= ava_4a.Text) And (need_1b.Text <= ava_4b.Text) And (need_1c.Text <= ava_4c.Text) Then
ava_5a.Text = Convert.ToInt32(ava_4a.Text) - Convert.ToInt32(need_1a.Text) + Convert.ToInt32(max_1a.Text)
ava_5b.Text = Convert.ToInt32(ava_4b.Text) - Convert.ToInt32(need_1b.Text) + Convert.ToInt32(max_1b.Text)
ava_5c.Text = Convert.ToInt32(ava_4c.Text) - Convert.ToInt32(need_1c.Text) + Convert.ToInt32(max_1c.Text)
need1 = 4
ElseIf (need_5a.Text <= ava_4a.Text) And (need_5b.Text <= ava_4b.Text) And (need_5c.Text <= ava_4c.Text) Then
ava_5a.Text = Convert.ToInt32(ava_4a.Text) - Convert.ToInt32(need_5a.Text) + Convert.ToInt32(max_5a.Text)
ava_5b.Text = Convert.ToInt32(ava_4b.Text) - Convert.ToInt32(need_5b.Text) + Convert.ToInt32(max_5b.Text)
ava_5c.Text = Convert.ToInt32(ava_4c.Text) - Convert.ToInt32(need_5c.Text) + Convert.ToInt32(max_5c.Text)
need5 = 4
End If
i have this code, the first condition is satisfied but it doesn't run the code.
Use Val ()
Without val() its a string comparision.
If (Val(need_1a.Text) <= Val(ava_4a.Text)) And (Val(need_1b.Text) <= Val(ava_4b.Tex)t)
And (Val(need_1c.Text) <= Valava_4c.Text)) Then
ava_5a.Text = Convert.ToInt32(ava_4a.Text) - Convert.ToInt32(need_1a.Text) +
Convert.ToInt32(max_1a.Text)
ava_5b.Text = Convert.ToInt32(ava_4b.Text) - Convert.ToInt32(need_1b.Text) +
Convert.ToInt32(max_1b.Text)
ava_5c.Text = Convert.ToInt32(ava_4c.Text) - Convert.ToInt32(need_1c.Text) +
Convert.ToInt32(max_1c.Text)
need1 = 4
ElseIf (Val(need_5a.Text) <= Val(ava_4a.Text)) And (Val(need_5b.Text) <=
Val(ava_4b.Text)) And (Val(need_5c.Text) <= Val(ava_4c.Text)) Then
ava_5a.Text = Convert.ToInt32(ava_4a.Text) - Convert.ToInt32(need_5a.Text) +
Convert.ToInt32(max_5a.Text)
ava_5b.Text = Convert.ToInt32(ava_4b.Text) - Convert.ToInt32(need_5b.Text) +
Convert.ToInt32(max_5b.Text)
ava_5c.Text = Convert.ToInt32(ava_4c.Text) - Convert.ToInt32(need_5c.Text) +
Convert.ToInt32(max_5c.Text)
need5 = 4
End If