Insert into table KUDU by datastage - impala

I am writing to enquire about a problem in my process:
I have a Kudu table and when I try to insert by datastage (11.5 or 11.7) a new row where the size is bigger than 500 characters using the Impala JDBC Driver I receive this error:
Fatal Error: The connector failed to execute the statement: INSERT INTO default.tmp_consulta_teste (idconsulta, idcliente, idinstituicao, idunidadeinst, datahoraconsulta, desccpfcnpj, idcentral, idcontrato, idusuario, valorconsulta, descretornoxml, idintegracaosistema, nomeservidor) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?). The reported errors are:
[SQLSTATE HY000] java.sql.SQLException: [Cloudera]ImpalaJDBCDriver Error getting the parameter data type: HIVE_PARAMETER_QUERY_DATA_TYPE_ERR_NON_SUPPORT_DATA_TYPE.
**************How can I fix it? I need to load that information. **********

I had similar problem where the error I received was :
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw
exception [Request processing failed; nested exception is
org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback;
uncategorized SQLException for SQL [update service set comments =? where service_name
="Zzzzz";]; SQL state [HY000]; error code [500352]; [Simba]
[ImpalaJDBCDriver](500352) Error getting the parameter data type:
HIVE_PARAMETER_QUERY_DATA_TYPE_ERR_NON_SUPPORT_DATA_TYPE; nested exception is
java.sql.SQLException: [Simba][ImpalaJDBCDriver](500352) Error getting the parameter
data type: HIVE_PARAMETER_QUERY_DATA_TYPE_ERR_NON_SUPPORT_DATA_TYPE] with root cause
I referred to the last most answer in the below link:
https://community.cloudera.com/t5/Support-Questions/HIVE-PARAMETER-QUERY-DATA-TYPE-ERR-NON-SUPPORT-DATA-TYPE/td-p/48849
I did the following:
1.Ensure the table is a Kudu table.
Instead of jdbcTemplate.query I did jdbcTemplate.batchUpdate in order to use a
PreparedStatement , did SetObject in PreparedStatement.
jdbcTemplate.batchUpdate(UpdateComment, new BatchPreparedStatementSetter(){
#Override
public int getBatchSize() {
return 1;
}
#Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
ps.setObject(1, comments);
}
});

Related

Prepared statement - with SET of run-time configuration parameters - not working

Using PG14, Hikari pool, Kotlin 1.6
I get the following error when calling, for example, a SET query:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
val input = "yes"
connection.prepareStatement("SET log_connections TO ?")
.apply {
setString(1, input)
}.use {
it.execute()
}
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
Position: 22
at app//org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2675)
at app//org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2365)
at app//org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:355)
at app//org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:490)
at app//org.postgresql.jdbc.PgStatement.execute(PgStatement.java:408)
at app//org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:167)
at app//org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:156)
at app//com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
at app//com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)
I'm trying to SET run-time configuration parameters of PostgreSQL from code by creating prepared statement and set its parameters safely, but I'm getting error while running such statement. Are there any limitations for creating prepared statements that might be limiting creation of such SET statement?
You can't pass a dynamic parameter using the SET command. You need to use the set_config() function:
val input = "yes"
connection.prepareStatement("select set_config('log_connections', ?, false)")
.apply {
setString(1, input)
}.use {
it.execute()
}

Not able to save a model record with auto generated ID

I tried to save a new row to DB like this
#SuppressWarnings("unchecked")
#Modifying
public SMSIncoming save(#Param("smsIncoming") SMSIncoming smsIncoming);
here I am not setting Id as its like below:-
SMSIncoming smsIncoming = new SMSIncoming();
smsIncoming.setSender("6476963460");
smsIncoming.setReceiver("6475603720");
smsIncoming.setMsg("Testing Incoming messages");
#Id
#GeneratedValue
private Long id;
It should be auto generated while saving it thru
#SuppressWarnings("unchecked")
#Modifying
public SMSIncoming save(#Param("smsIncoming") SMSIncoming smsIncoming);
JpaRepository<SMSIncoming, Long>
but here also I am getting a lot of exceptions, I tried all options (AUTO, TABLE, SEQUENCE and IDENTITY) not able to get thru, so next I thought to get the max id from table and save by increment it. In this approach as well I am facing issues.
Issue traces while saving with IDENTITY keyword in id :-
`2019-03-26 11:32:15.347 INFO 5828 --- [ main]
c.a.s.service.SmsPluginApplicationTests : --Application Started--
smsrec.toString():::::::com.avaal.sms.model.SMSIncoming#4c6bba7d
Hibernate: insert into dbo.ozekimessagein (id, msg, msgtype, operator,
receivedtime, receiver, reference, sender, senttime) values (null, ?, ?,
?, ?, ?, ?, ?, ?)
2019-03-26 11:32:16.029 WARN 5828 --- [ main]
o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 339, SQLState: S0001
2019-03-26 11:32:16.029 ERROR 5828 --- [ main]
o.h.engine.jdbc.spi.SqlExceptionHelper : DEFAULT or NULL are not allowed
as explicit identity values.
Inside test catch block::::::::::
org.springframework.dao.InvalidDataAccessResourceUsageException: could
not execute statement; SQL [n/a]; nested exception is
org.hibernate.exception.SQLGrammarException: could not execute statement
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:279)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:253)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:527)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:135)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
Issue traces while saving with SEQUENCE or AUTO keyword in id :-
`#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE/AUTO)
private long id;`
smsrec.toString():::::::com.avaal.sms.model.SMSIncoming#5d717f19
Hibernate: call next value for hibernate_sequence
2019-03-26 12:29:06.493 WARN 15412 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 102, SQLState: S0001
2019-03-26 12:29:06.494 ERROR 15412 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : Incorrect syntax near 'value'.
Inside test catch block::::::::::
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:279)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:253)
Issue traces while saving with TABLE keyword in id :-
`#Id
#GeneratedValue(strategy = GenerationType.TABLE)
private long id;`
`smsrec.toString():::::::com.avaal.sms.model.SMSIncoming#69e2fe3b
Hibernate: select tbl.next_val from hibernate_sequences tbl where
tbl.sequence_name=? for update
2019-03-26 12:33:33.157 ERROR 15896 --- [main]
o.hibernate.id.enhanced.TableGenerator : HHH000351: Could not read or
init a hi value com.microsoft.sqlserver.jdbc.SQLServerException: Line 1: FOR UPDATE clause allowed only for DECLARE CURSOR. at
com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:259) ~[mssql-jdbc-6.4.0.jre8.jar:na] at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1547) ~[mssql-jdbc-6.4.0.jre8.jar:na] at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:548) ~[mssql-jdbc-6.4.0.jre8.jar:na]`

sqlException when use ActiveJDBC

I use ActiveJDBC and Oracle 11g DB. When I use saveIt, i get java.sql.Exception. When I get instance or list of it, everything ok.
What I do wrong?
Exception in thread "main" org.javalite.activejdbc.DBException: java.sql.SQLException: Invalid argument
зове, query: INSERT INTO dept (DEPTNO, DNAME, LOC) VALUES (?, ?, ?), params: 45, sdfa, fdg
at oracle.jdbc.driver.AutoKeyInfo.getNewSql(AutoKeyInfo.java:187)
at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:5704)
at org.javalite.activejdbc.DB.execInsert(DB.java:598)
at org.javalite.activejdbc.Model.insert(Model.java:2698)
at org.javalite.activejdbc.Model.save(Model.java:2597)
at org.javalite.activejdbc.Model.saveIt(Model.java:2524)
at JavaHomeTask.Dept.addPersistence(Dept.java:72)
at JavaHomeTask.App.addRow(App.java:103)
at JavaHomeTask.App.main(App.java:50)
Caused by: java.sql.SQLException: Invalid argument
... 9 more
And here is my code:
public void addPersistence() throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Dept d = new Dept();
String value;
for (String s : getAttributesNames()) {
System.out.println("Enter " + s + " and press Enter button:");
value = reader.readLine();
d.set(s, value);
}
d.saveIt();
}
public List<String> getAttributesNames() {
return Arrays.asList("DEPTNO", "DNAME", "LOC");
}
The reason of the probleb is that ActiveJDBC uses id column as a Primari Key in table for recognizing which operation - INSERT or UPDATE should be used. And if table doesn't has such column, programmer should specify PK manually using #IdName("nameOfColumn") annotation. More information you can find here

Add New custom option value using web service in Magento API

I'm integrating Adempiere with Magento Synchronizing Products , i want to create a custom options but im getting error
XML-RPC Error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'price_type' cannot be null, query was: INSERT INTO `catalog_product_option_type_price` (`option_type_id`, `store_id`, `price`, `price_type`) VALUES (?, ?, ?, ?)
i have given the value Product_DATA.put("price_type", "percent"); code:
public int CreateCustomOptions(String sessionid,Integer product_id,String Option,String o_value , String o_sku, String price)
{
HashMap Product_DATA = new HashMap();
Product_DATA.put("title", o_value);
Product_DATA.put("price",price);
Product_DATA.put("price_type", "percent");
Product_DATA.put("sku", o_sku);
Vector ARGS = new Vector();
ARGS.add(sessionid);
ARGS.add(new String ("product_custom_option_value.add"));
ARGS.add(new Object[] {110,Product_DATA});
this.newRequest(remoteHost, "", sessionid, "call", ARGS);
Object RESULT = (Object) this.sendRequest();
}
Try to use (String) cast to force , or use string valueof
http://www.tutorialspoint.com/java/java_string_valueof.htm

java.sql.SQLException: operation cannot be mixed with Oracle-style batching

I'm not really sure about the mixing JDBC and Oracle batching... I read that I can't mix it on one instance of preparedStatment ... because of: Oracle Update Batching Models - Using both batching models in same application
But I also find something saying that it can't be mixed even in a single application... http://docs.oracle.com/cd/B10500_01/java.920/a96654/oraperf.htm
So know I'm not sure where the problem is...
I create a new prepared statment in each call of function:
public void functionCall(int Id)
PreparedStatement insStm = null;
String featureName = "";
String featureTypeName = "";
String sql = "BEGIN insert into " + TABLE_FEATURE_INSET + " values (?, ?, ?, ?); EXCEPTION WHEN others THEN IF SQLCODE != -1 THEN RAISE; END IF; END;";
insStm = getConnection().prepareStatement(sql);
for(xxx)
for (yyy) {
for (zzz) {
insStm.setObject(1, TypeName);
insStm.setObject(2, tableName);
insStm.setObject(3, sourceId);
insStm.setObject(4, Id);
insStm.addBatch();
}
}
// per feature
insStm.executeBatch();
}
statement .close();
}
And then I sometimes get an error...:
Caused by: java.sql.SQLException: operation not allowed: operation
cannot be mixed with Oracle-style batching
Maybe is problem that prepareStatment can be from same connection? I'm really not sure about this.
Can somebody help me? Thanks
EDIT:
That error is caused by this call: insStm.addBatch();