i wanted to ask what happens when collection.deleteMany{()} is executed in java without any query or empty string. Will it fail to execute (as in nothing is deleted) or will it drop the whole database?
in deleteMany() when you execute without query it returns error
if you want to delete whole collection you could use deleteMany({})
Related
We are using hibernate as an ORM in our project along with Spring framework. Today, I faced one issue where one named query (basically a select query) is giving inconsistent results when being called multiple times. Hit to this select query is not in a loop whereas it is from the front end. So, when i am performing a same operation multiple times from the front end, sometimes query is fetching the correct data from the DB but sometimes not.
Example:(Sample code)
Query query = session.getNamedQuery("select debitid from ABCMstrEntity where entitynum=: entitynum and isopen=:Y");
query.set(........);
..
List<Object[]> list = (List<Object[]>)query.list;
In first 4 attempts, i got correct data in the list object.
In my 5th attempt, i got empty list object although data was present in db for the provided inputs. When i checked it using db query logs at DB end, i found that, there was no hit at DB end for my 5th attempt. So it seems, something has gone wrong here.
I also checked for cache related settings in hibernate in my project but we are not caching query results in any of the cache regions. Also, there was no exception in the applications logs.
Please someone help me on this issue in analyzing and fixing it.
I am trying to run a insert statement which will help me to create user account for my following api calls.
I looked at JMeter JDBC request which has select/update/ect... i don't see insert query type.
does anyone know how can i run some insert query to create the user for my database?
thanks
L.
You should use Update Statement Query type also for inserts
Update Statement - use this for Inserts and Deletes as well
You may use also Prepared Update Statement type:
Prepared Update Statement - use this for Inserts and Deletes as well
In JDBC terms "insert" equivalent is update therefore you need to choose Update Statement from the "Query Type" dropdown:
You might also find How to Create Test Data in a Database with JMeter useful, it provides more insight and examples.
Helo,
I am a beginner java programmer.
I need to update multiple rows with a query using mysql database and java codes.
I need to update the age field (data type int) in the database based on the current date. I believe I need to iterate and use the hasnext ... but I just unable.
If you need to update all the rows using a common logic based on current date, write a single update query and execute it. It will update all the rows. If logic is different then use updatble result set.
Are you facing a problem in executing an update query or is it with the iteration on integer array. Please provide more details. And if you are attempting to update similar data, try doing it using a single query, as executing queries in loop is not recommended.
What I mean is I have a program that executes inserts in batches of 100k. Each one of these inserts is assigned a new ID from a sequence on insert. I want to keep the batch process for obvious reasons, but I also need to then pull out each ID as it is created and do things with it before I move on to the next insert. Is there a way to do this?
Things work differently in PostgreSQL than MySQL. First you have to write your insert as:
INSERT INTO foo (...) VALUES (...)
RETURNING id;
The RETURNING id is important as that tells the insert statement to return something. Then you should be able to pull back the id as what you could expect from a select statement.
I am not quite sure how the JDBC driver for PostgreSQl implements this regarding batch processing though. If you have to, you could probably modify this to store the id in a temporary table or something that you could query from after.
I am just getting into ibatis with SqlMap for the first time and I have run into a problem. I have figured out how to insert, delete, update, and select single records. Now however I am trying to write a select statement that will bring back more than a single record and I am getting mapping errors. How do I specify that the result should be a List of my custom objects?
I've figured it out. Using java I simply had to use the queryForList function instead of queryForObject.