Unable to fathom update count INSERT on billions of rows - java

I am running a Netezza SQL query that is creating a table from a select statement returning almost 8 billion rows. Here is the query:
CREATE TABLE
table1 AS
(
SELECT
column1
FROM
table2 qt
WHERE
qt.column1 = '2016-04-04'
UNION ALL
SELECT
column1
FROM
table3 qt
WHERE
qt.column1 = '2016-04-04'
)
The driver is throwing this error:
org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [UNDEFINED]; error code [0];
--- The error occurred while applying a parameter map.
--- Check the statement (update failed).
--- Cause: Unable to fathom update count INSERT 0 7779737732
Does anyone know what's causing this?

I think you are running into a JDBC driver limitation. If you run a INSERT, UPDATE, CREATE AS SELECT via JDBC and the number of rows INSERTed, UPDATEd or CREATEd exceeds 2147483647, you will receive an error message similar to the following:
Unable to fathom update count INSERT 0 5120000160
The above error message may be different given whether an INSERT, UPDATE or CREATE as SELECT and given the number of rows actually affected. This is a limitation of JDBC specification itself.
Thanks,
Sanjit

Related

java.sql.SQLSyntaxErrorException: ORA-00903: invalid table name in Java on select count on function return

I am getting Table not found exception for the following query
select count(1) from (pkg_queries.query1function(id));
Type table_type is Table of record_type
query1function is a function from the package which returns table_type.
In java code on prepared statement execution, the select query gives an Invalid Table name Exception. The Same query is successfully executed in Oracle SQL developer.
Is it possible that it is a Java Oracle Driver issue? How to resolve it?

Java prepared statement throwing SQLIntegrityConstraintViolationException: Invalid argument(s) in call

I am trying to insert a record into DB (Oracle) through Java code. When it is preparing statement at that time it is throwing an exception
java.sql.SQLIntegrityConstraintViolationException: Invalid argument(s) in call
on below line of code:
PreparedStatement ps = connection.prepareStatement(INSERT_QUERY);
and the insert query is:
private static final String INSERT_QUERY = "INSERT INTO ABC ( uid,created_datetime,status,update_datetime,b_id,ref_no,ref_dt,sor,b1_id,c_code,base,name,src,trn_date,country,pr,cv,features,scoring_time_ms,scoring_request_time_ms,preprocessing_time_ms,postprocessing_time_ms,overall_time_ms )VALUES ( ?,current_timestamp,?,current_timestamp,?,?,?,?,?,?,?,?,?,current_timestamp,?,?,?,?,?,?,?,?,? )";
When I debugged the code I found that when it is preparing statement connection.prepareStatement(INSERT_QUERY); insert query is showing as below:
INSERT INTO ABC ( uid,created_datetime,status,update_datetime,b_id,ref_no,ref_dt,sor,b1_id,c_code,base,name,src,trn_date,country,pr,cv,features,scoring_time_ms,scoring_request_time_ms,preprocessing_time_ms,postprocessing_time_ms,overall_time_ms )VALUES ( ?,systimestamp,?,systimestamp,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? )
It is changing current_timestamp to systimestamp and also I have 3 current_timestamp in the query and it is missing 3rd one while debugging.
I have deleted all the records from database. DB is empty and it has no constraints, only primary key.
Can anyone help me on this issue. Why is this happening and how can I resolve this?
SQLIntegrityConstraintViolationException points to a db constraint violation. Check the for primary/unique/foreign keys in the table "ABC". Just based on the insert statement, can assume uid must be unique.
This issue is resolved. It was build issue. It was not taking updated code so getting that error. Deleted everything from .m2 dir and build it again and this error got disappeared.

ORA-01722 invalid number error with oracle database in hibernate query language

I am using query
select x
from table1 x
order by x.it desc
It is working good when I use it with Postgres but whenever i change the database and start to use oracle it is throwing an error that is,
ERROR -- ORA-01722: invalid number
org.hibernate.exception.SQLGrammarException: could not execute query

The column name is not valid - error

I am getting this error while I am fetching value from resultset.
Error : com.microsoft.sqlserver.jdbc.SQLServerException: The column name company.short_name is not valid
CASE 1 :
select company.short_Name,location_name from company,location;
this query is executing fine on SQL Server but in my java code when I trying to retrieve value like resultset.getString("company.short_name"); that time this give the above error.
CASE 2 :
select company.short_Name short_name,location_name from company,location;
and retrieve value like resultset.getString("short_name"); than it work fine with both database MySQL and MSSQL.
I am migrating my database from MySQL to MSSQL.above case 1 is work fine in MySQL, but why it is not work in MSSQL?
resultset.getString("company.short_name"); is wrong here. No need to specifying fully qualified name while trying to fetch the data in your application. Just specify the column name like resultset.getString("short_name");.
Cause even though you say select company.short_Name ... query out the column name as short_Name since that's what defined in table schema.
In case both tables has same column which may result in ambiguity, give a alias name to the columns like
select company.short_Name as company_shortname,
location.short_Name as location_shortname,
location.location_name from company,location;
add the following to your application.properties file
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
When you do
select company.short_Name,location_name from company,location;
This query outs the column name short_Name and resultSet would also have short_Name
since the company.short_name doesnt exist you get an error.
the function resultset.getString(String columnLabel)
Retrieves the value of the designated column in the current row of this ResultSet object as a String in the Java programming language.
Parameters:
columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
Returns:
the column value; if the value is SQL NULL, the value returned is null
Throws:
SQLException - if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set
in the function resultset.getString(String columnLabel), the arg is a column name for executing sql, the statement select company.short_Name,location_name from company,location; will get a result set, which has table headers short_Name,location_name

Derby Database : delete records which their timestamp greater than 2 hours

i tried to write a named query in my Entity Java Bean class , and tried also to write the same query as a native query , its job is to delete records which difference between their timestamp column and current time stamp, are greater than 2 hours.
my query :
DELETE FROM APP.WEATHER WHERE timestampdiff(SQL_TSI_HOUR,APP.WEATHER.SINCE,CURRENT_TIMESTAMP) > 2;
but it failed , and this error message appeared to me :
Error code -1, SQL state 42X04: Column 'SQL_TSI_HOUR' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'SQL_TSI_HOUR' is not a column in the target table.
Line 1, column 1

Categories