SUM of a query sql column at dataservice wso2 - wso2

here is the sql query and it does not accept the sum on dataservice wso2
SELECT nom, SUM(note) as totalnote from etudiant where nom =?;
when i test i get this error :
<axis2ns4:ds_code>DATABASE_ERROR</axis2ns4:ds_code>
<axis2ns4:nested_exception>java.sql.SQLException: Can not issue executeUpdate() or executeLargeUpdate() for SELECTs</axis2ns4:nested_exception>

Related

How to handle SQL parameters with Apache Calcite Planner (Facade Interface)?

I need some help with processing queries using Apache Calcite, I am currently using Planner to process my queries.
My code looks like this:
// custom config
FrameworkConfig frameworkConfig = Frameworks.newConfigBuilder()
.parserConfig(parserConfig)
.defaultSchema(rootSchema)
.sqlToRelConverterConfig(convertConfig)
.operatorTable(operatorTable)
.build();
Planner planner = Frameworks.getPlanner(frameworkConfig);
String sql = "Select id, name from t where id in (?, ?)";
SqlNode parsedSqlNode = planner.parse(sql);
SqlNode validatedSqlNode = planner.validate(parsedSqlNode);
RelRoot relRoot = planner.rel(validatedSqlNode);
PreparedStatement preparedStatement = RelRunners.run(relRoot.rel);
preparedStatement.setLong(1, 11111);
preparedStatement.setLong(2, 22222);
ResultSet resultSet = preparedStatement.executeQuery();
// ....
It works fine without SQL parameters, but there are some queries with SQL parameters.
While using SQL parameter and setting the parameter(preparedStatement.setLong), I got the following error message:
Caused by: java.sql.SQLException: parameter ordinal 1 out of range
at org.apache.calcite.avatica.Helper.createException(Helper.java:60)
at org.apache.calcite.avatica.AvaticaPreparedStatement.getParameter(AvaticaPreparedStatement.java:427)
at org.apache.calcite.avatica.AvaticaPreparedStatement.getSite(AvaticaPreparedStatement.java:434)
at org.apache.calcite.avatica.AvaticaPreparedStatement.setLong(AvaticaPreparedStatement.java:178)
SQL parameters are obviously not being handled correctly. What is the proper way to define and set SQL parameters when using Planner in a case like this?

fetch data in map from repository using JPA query

I want to get the data from table using this query:
select clientId, Count(countryID) from table groupBy countryID;
which gives me the count of country corresponding to clientId. Normally we fetch into the List<Object>.
How i can fecth these details into a Map<clientId, countryCount> with clientId as key and countryCount as value?

Create charts from SQL query

I want to create a chart from a join sql query between 2 tables in superset.
for example , I go to SQL Lab and execute this query :
select film, count("film") from rental r, payment p where r.rental_id=p.rental_id group by("film") order by count("film") limit 20;
This returns me a result but how to insert in a chart?
How to create chart from SQL query ?
In order to visualize the results from a query executed in SQL Lab, you first need to click on Explore (underneath the Results tab).
Once you are in exploration mode, you can change the "Visualization Type", under "Datasource & Chart Type".

Update with HQL error

Hi all i have the following code:
tx = session.beginTransaction();
Query query = session.createQuery("UPDATE com.nisid.entities.Payment set amount=:amount,paymentMethod=:method,paymentExpire=:expireDate"
+ "Where paymentId=:payid,actionId=:actionid");
query.setParameter("amount", amount);
query.setParameter("method", method);
query.setParameter("expireDate", expireDate);
query.setParameter("payid", projectId);
query.setParameter("actionid", actionId);
int resutl=query.executeUpdate();
Trying to do an update using HQL but i am getting error: galArgumentException: node to traverse cannot be null!
my table in the DB is called Payment and it has A COMPOSITE KEY ( projectId,actionId)
Could you please help me further???
The concept is that i have a JSP page which retrieves and displayes the results from DB retrieving info from Project Table, Payment Table and Action Table. Project has many to many relationship with Action and i am using Payment Table as the intermetiary table which holds the 2 FK of the other table.
You missed space before where, and replace , to and after where.
Query query = session.createQuery("UPDATE com.nisid.entities.Payment set amount=:amount,paymentMethod=:method,paymentExpire=:expireDate"
+ " Where paymentId=:payid and actionId=:actionid");

Retrieve a list of date from a SQL query

Is it possible to retrieve a List<Date> instead of a List<SomeBean> using Ebean ?
For example, I have this model:
Days(id, name, day);
I'd like to do something like:
List<Date> dates = Ebean.createQuery(Date.class, "SELECT day FROM days").findList();
Of course, this doesn't work and returns this:
PersistenceException: java.util.Date is NOT an Entity Bean registered with this server?
How can I do that?
you can use sqlQuery see SqlQuery in Ebean :
The database retrieves time and date data with a type LocalDateTime
String sql = "select day from days";
List<SqlRow> row = DB.sqlQuery(sql).findList();
List<LocalDateTime> days = row.stream().map(r->(LocalDateTime) r.get("day")).collect(Collectors.toList());