DateTimeParseException thrown for unknown reason [closed] - java

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Here is the full error line:
java.time.format.DateTimeParseexception: Text '01-Jan-2020' could not be parsed at index 0
Here is the code I am using that throws the error:
val DATETIME_FORMAT = DateTimeFormatter.ofPattern("d-MMM-yyyy").withZone(ZoneId.of("UTC"))
val parsedTime = DATETIME_FORMAT.parse(input)
the input variable is '01-Jan-2020' as seen in the error line.
I have looked at many similar questions to this one but it's not the expected solution. Can anybody enlighten me on how to solve this problem?

You have to set Locale as second parameter ofPattern method, look below (working code in java)
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MMM-yyyy", Locale.ENGLISH).withZone(ZoneId.of("UTC"));
var parsedTime = dateTimeFormatter.parse("01-Jan-2020");

Related

java equivalent for scala classOf[] [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
Can any one help me with the Java equivalent of this?
wordCountRDD.saveAsNewAPIHadoopFile(outputFile,classOf[Text],classOf[IntWritable],classOf[TextOutputFormat[Text,IntWritable]])
I tried below : but it give me error at TextOutputFormat<>(Text,IntWritable) ..
wordCountRDD.saveAsNewAPIHadoopFile(
output,
Text.class,
IntWritable.class,
TextOutputFormat<>(Text,IntWritable)
context.hadoopConfiguration());
Here:
TextOutputFormat<>(Text,IntWritable)
You have to pass the class instead:
TextOutputFormat.class
But note: the java type system doesn't allow you to express something like. TextOutputFormat<Text,IntWritable>.class! See here for why that is.
From that point of view, TextOutputFormat.class seems to be your only option.

How to fix NumberFormatException for input string "0.40" [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
i am trying to convert string value to long for further processing but this error occurs everytime
13-Feb-2019 13:15:35.593 SEVERE [http-nio-8084-exec-570] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service()
java.lang.NumberFormatException: For input string: "0.40"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.parseLong(Long.java:631)
You are trying to store the value 0.4 in a long. Long doesn't support floating point values, so you have to use either float or double.
Exceptions like this one can be handled in your code using try and catch.

Oracle compare date [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have a table with date field in it. User passes month and year. I need to return records where its date has passed year and month.
For example.
Record in table: time:'2016-01-10', time:'2016-01-01', time:'2015-01-01'.
Passed values: year:'2016', month:'01'.
And the return should be first and second records.
How to do it in oracle?
PS. I tried smth like this time>=date'2016-01-01' and time<=date'2016-01-31' but if the last day is not 31, I will get an exception.
Read this date formatting
If I understand you correct you want something like this
To_char(Your_date_col, 'YYYYMM' ) = yearparam ||monthparam

Joda-Time cannot find class "forPattern()" [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
im trying format a date using Joda-Time v 2.8.2, all the similar answers i have found say to use a method forPattern(), but with the version I am using it tells me that there is no such method(), am I using it incorrectly? or is this method deprecated or something? if so, what method is it replaced with if any?
Relevant code:
static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
public String timeSince(String dateString) {
org.joda.time.format.DateTimeFormatter formatter =
new DateTimeFormat.forPattern(DATE_FORMAT);
Seconds secondsSince = Seconds.secondsBetween(DateTime.parse(dateString, formatter),
DateTime.now());
...
}
cannot find class “forPattern()” is one thing, and tells me that there is no such method() is a totally different thing.
What is actually happening is that new Class.Function() is a syntax error.
So, java got confused, it thinks you must be trying to invoke a constructor, so it is telling you that it cannot find the class that contains such a constructor.
Solution: drop the new.
forPattern is a static method. Remove the new keyword
DateTimeFormatter formatter = DateTimeFormat.forPattern(DATE_FORMAT);

sql BIT to Java [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
My sqlserver table has a column designed as a BIT datatype. It has values 1 and 0s
Then in my Java code, I do
result = new ArrayList
result.add( (Boolean)(rs.getBoolean("columnName")));
Then when I read the value from the list - it shows as Long.
According to everything I find, it says hat a BIT datatype is supposed to map to boolean.
Why does it come as Long?
What can be done to fix this?
You can call getBoolean directly and let it take care of all the casting/coverting:
result.add(rs.getBoolean("columnName"));

Categories