mysql : Can't find record in table - java

In my java program an update query is used like below,
update unsub_tbl set stat=1 where stat=0 and emp_id='4441' and action='1';
if unsub_tbl is empty, then trying to update using above update query gives exception:
java.sql.SQLException: Can't find record in 'unsub_tbl'
But it's not giving the exception all the time for same condition. Why does it only give the exception sometimes?

It seems that it is a bug with MySQL 4.0.14+
Refer MySQL Bugs

Related

ERROR: column 'nameofcolumn' does not exist, unable to update field

I'm trying to update a field so i can test liquibase's functioning on my job. I'm using this
syntax
UPDATE "Country" SET "name" = 'Perúpe' WHERE "id" = 10;
But it will throw an error that says:
Caused by: org.postgresql.util.PSQLException: ERROR: column "Perúpe" does not exist
Which is not a column, it is a value that i'm trying to input so i know liquibase is working.
It is working with a db that was done outside liquibase, and it has only 3 liquibase inputs. Those are ok. When i try to enter a new one, it will crash and stop the app, until i erase that test.
I think my syntax could be wrong. It moved from the table (relation does not exist) to the value of my entry. What could i be doing wrong?
This has been asked and answered previously. Error: Column does not exist in postgresql for update
As Adrian wrote in their comment above, using single quotes instead of double quotes is the reported solution.

Java Calling a MSSQL query containing a sequence Get Invalid Object

I have written a query that has NEXT VALUE FOR AVS_Interface_ControlID as controlID which is a valid sequence. I get the error:
Caused by: java.sql.SQLException: Invalid object name 'AVS_Interface_ControlID'.
When I run this exact query in MSSQL Server Management Studio, I do not get an error and the sequence is displayed correctly and increments. I've tried using dbo. and DBName.dbo. and those don't help. I am logging into the DB as SA for both attempts.
Is "Next value for" not allowed with Java prepared statement calls? or am I missing something?

Update and Return Updated column using returning keyword in same query in java jdbc code

update account set lastusedval=lastusedval+1 where isactive=1 returning
lastusedval;
How to execute above query in java?
when i tried to execute in oracle its working but in java hibernate/jpa no way to store return value in update query.
By executing above query intention is to apply lock on db level when more than 1 request comes
Using jdbc prepared statement with registeroutparameter might help you to resolve this issue.
Creating an UPDATE RETURNING query in Hibernate

Pagination is not working when calling MySQL Stored Procedure using Hibernate

I have a MySQL Stored Procedure click here for stored procedure and calling the Procedure using Hibernate
Hibernate Code:
int ps=5;
SQLQuery query=session2.createSQLQuery("CALL AbsentReportproc(:_fromdate,:_todate)");
query.setParameter("_fromdate", fromdate);
query.setParameter("_todate", todate);
query.setFirstResult(ps*(pno-1));
query.setMaxResults(ps);
List<Object[]> empList=query.list();
when I execute above code I'm displayed with the following Error Message:
org.hibernate.exception.SQLGrammarException: could not execute query
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit 5' at line 1
Note:If i remove the below statement from the code,I'm displayed with all records in a single jsp Page
query.setMaxResults(ps);
Could any one give me the solution what was the Problem?
thanks...
It is clearly a jdbc driver error that you are using;
Also try this with setFetchSize , and if this doesn't work also then,
I would suggest not to get the details out of the query in chunks if you want to display them all and there is not much data and you should rather store all the data without calling this method query.setMaxResults(ps); into a collection.
And when you want to display that data in pages, then get subList in case you are using List, to break the data at the application level and then display it on your view that is jsp in this case.

Hibernate: Issues with running update query

I see there are two ways to create update query in Hibernate. First you can go with the standard approach where we have hql like:
Query q = session.createQuery("update" + LogsBean.class.getName() + " LogsBean " + "set LogsBean.jobId= :jobId where LogsBean.jobId= :oldValue ");
q.setLong("jobId", jobId);
q.setLong("oldValue", 0);
return q.executeUpdate();
or we can go and run
getHibernateTemplate.saveorupdate(jobId);
Now am getting java.lang.IllegalArgumentException: node to traverse cannot be null! on running first query and am not sure hwo to provide condition in getHibernateTemplate example, i want to update jobIds in log table whose value matches 0 and so i want to run something like
Update logs set jobId = 23 where jobId = 0
Above is the simple sql query that I am trying to run but I want to run this via hibernate, tried couple ways but it is not working, any suggestions?
Update:
As noted by Jeff, issue was not having space after update and so that issue got resolved but still values are not updated, i have updated show_sql true for hibernate and checking what could be the cause of the issue, will be running query generated by hibernate to run again db and see if records are updated.
Just a few things that might help you to resolve this:
What does .executeUpdate() return, 0 (as it did not update any
rows)?
Does it throw a HibernateException that you are
silently catching or rethrowing?
Which FlushMode do you have configured?
Does the update get to the DB? You could switch on the query log for your DB server.

Categories