I have a column called PAYMENT_REF that contains value of the following sequence:
DBC2020999999999999
It will always have the length 19 and starts with DBC followed by the year which is this part: DBC2020
The following numbers after the year is a sequence number which is 999999999999.
Basically I need to do a query that find the max value only from the sequence number ignoring the static DBC and year 2020.
Basically when I run the following query on oracle developer ide I get the correct result:
select MAX(SUBSTR(PAYMENT_REF,7,19))
from PAYMENT p
where PAYMENT_REF is not null;
So I tried the following query which looks should get the max value of:
public interface PaymentRepository extends JpaRepository<Payment, String> {
#Query(" select MAX(SUBSTRING(p.paymentRef,7,19)) from payment p where p.paymentRef is not null")
int getMaxRefNumber();
}
But I get a compilation error cannot resolve symbol: payment, any idea what I a missing here please?
I guess you should correct your query in the following way:
#Query("select MAX(SUBSTRING(p.paymentRef, 8, 12)) from Payment p where p.paymentRef is not null")
String getMaxRefNumber();
As it is stated in the documentation:
SUBSTRING
Extracts a portion of a string value. The second argument denotes the starting position, where 1 is the first character of the string. The third (optional) argument denotes the length.
1 8
| |
DBC2020999999999999
\ /
12 chars
P.S. To be honest I wasn't able to cast string to number in the hql.
The statement like the following:
select MAX( cast(SUBSTRING(p.paymentRef, 8, 12) as long) )
from Payment p where p.paymentRef is not null
will not work, the following exception is raced:
java.lang.IllegalArgumentException: Type specified for TypedQuery [java.lang.Long] is incompatible with query return type [class java.lang.String]
at org.hibernate.internal.AbstractSharedSessionContract.resultClassChecking(AbstractSharedSessionContract.java:863)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:817)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:23)
Related
I am running a simple insert using jooq:
InsertValuesStep6<...>
insertInto =
withContext()
.insertInto(
MyTable,
MyTable.ID);
for (Integer id : ids) {
insertInto = insertInto.values(id);
}
insertInto.execute();
I simplified it a bit for the question, there are couple of more fields in each row.
It usually works fine, but once in a while get an exception: org.postgresql.util.PSQLException: No value specified for parameter 1.
So I suspect it's not a syntax issue but scale issue.
Maybe the actual query is trimmed by jooq somehow?
I have the following query:
FOR i IN items
COLLECT otherId = i._from WITH COUNT INTO counter
FILTER counter > ##myParameter
RETURN otherId
Doesn't matter if it's executed from Java or the ArangoDB Web Interface, I always get the same error back:
Query: AQL: bind parameter '#myParameter' has an invalid value or type (while parsing)
If I replace ##myParameter with a number it works.
Any idea? In Java I have tried with Integer, Long, BigInteger with no luck :-(
ArangoDB COMMUNITY EDITION v3.2.5
Non-collection parameters require a single #
I am using Java and querying InfluxDb as shown below,
queryResult1 = influxDB.query(new Query("SELECT last(timestamp) FROM vale" , eachDatabase));
This statement is working fine, but when the name have any of the special character for e.g. if measurement name is "vale-ab" instead of vale, it won't work.
Error i am getting is:
java.lang.RuntimeException: {"error":"error parsing query: found -, expected ; at line 1, char 34"}
Any idea how can i escape measurement name inside the queries.
You need to wrap your measurement with double quotes ".
Bad:
select * from a-b
ERR: error parsing query: found -, expected ; at line 1, char 16
Good:
select * from "a-b"
name: a-b
time tag1 value
---- ---- -----
1434089562000000000 10i 5
I don't have Java installed on this machine but the code below should solve your problem.
queryResult1 = influxDB.query(new Query("SELECT last(timestamp) FROM \"vale-vale\"" , eachDatabase));
I am using text fields for displaying column names . For showing the corresponding name of the column I have tried the following method:
Method 1:
textField.setX(currentXPos);
textField.setY(0);
textField.setWidth(columnWidth);
textField.setPrintWhenDetailOverflows(false);
textField.setHeight(colDtlBandHeight);
textField.setStretchWithOverflow(true);
textField.setStretchType(StretchTypeEnum.RELATIVE_TO_BAND_HEIGHT);
textField.setStyle(normalFont);
textField.setBlankWhenNull(true);
JRDesignExpression expression = new JRDesignExpression();
expression.setValueClass(columnClass);
expression.setText("$F{" + columnName + "}");
But on using the above method it throws an exception saying:
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. Syntax error on token "ID", delete this token
value = SHIFT ID; //$JR_EXPR_ID=44$
2. Syntax error, insert ";" to complete BlockStatements
value = BILL NO.; //$JR_EXPR_ID=45$
3. Syntax error on token ".", invalid VariableDeclarator
value = BILL NO.; //$JR_EXPR_ID=45$
4. Syntax error on token "DATE", delete this token
value = BILL DATE; //$JR_EXPR_ID=46$
But on using the below lines the column Names are set correctly .
Method 2:
textField.setExpression(new JRDesignExpression("new String(\""+colTitle+"\")"));
My doubts are:
1. For displaying the data the first method mentioned is used . Then how come there are no exceptions in that case ?
2. Why did it throw those exceptions when the same method was used for displaying column names?
3. How did the 2nd method work ?
1.:
I suppose the data is properly enclosed in quotes.
2.:
Judging by the exception explanation (e.g. Syntax error on token "ID", delete this token) the interpreter sees two values, SHIFT and ID. It seems here that quotes are missing, e.g.
"SHIFT ID"
"BILL NO."
3.:
In your first example, you create a JRDesignExpression, set the value class and set the text.
The field isn't enclosed in quotes as seen in your lower example. It should look like this:
expression.setText("\"$F{" + columnName + "}\"");
Also, you didn't assign the expression to your textField:
textField.setExpression(expression)
I have this method to call a stored function from ORACLE, in java (spring) - using entity manager + createNativeQuery ..
(...)
String set_professional = "{? = call
pk_backoffice.set_professional(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?}";
//32 parameters IN
query = entity.createNativeQuery(set_professional);
(...)
And everytime I try to test it, it shows:
Positional parameter does not exist: 31 in query: {? = call (...)
But do I have something at position 31..it exists..
query.setParameter(31, prof.getFax()); // fax
Also, I started the parameters at 1 cause in previous exceptions it said it was 1-based
I've tried with a string and a null value instead of the get, still the same outcome..
About the query, I also counted the ? many times, so I'm sure it has 32 (for parameters) + 1(return - first ?)...
Can anyone help?
Found a solution, I replaced all ? for variables, even the first one, and the error disappeared.