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.
Related
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({})
I am currently trying to push some data from Java into BigQuery, in order to be able to make use of it only for the next query and then to get rid of it.
The data consists of 3 columns which exists in the table I want to query. Therefore, by creating a temporary table containing this data, I could make a left join and get the query results I am in need of.
This process will happen on a scheduled basis, having different sets of data.
Can you please tell me if that can be done ?
Many thanks !
Using the jobs.query API, you can specify a destinationTable as part of configuration.query. Does that help? You can control the table expiration time using the tables.update API and setting expirationTime.
Alternatively, you can "inline" the table as part of the query that you want to run using a WITH clause in standard SQL rather than writing to a temporary table.
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.
I have 2 DBs, Database A and Database B.
What I want to achieve:
build records from Database A and insert them to Database B
Process those records in my java app
What I'm currently doing:
I use two separate queries:
For (1) I use INSERT INTO ... SELECT ...
For (2) I perform another SELECT.
My solution works but it isn't optimal since I'm getting the records from Database A twice (instead of just one time).
Is there a way to execute the INSERT INTO ... SELECT ... and get the inner select result as a ResultSet?
I know I can perform only a SELECT and then insert the records in a batch, but thats a bit cumbersome and I want to find out if there's a cleaner solution.
Your cleaner solution look more cumbersome than simple read and write operation.
As you have to manipulate data in database B. You simply do this
Read Data from A to your app
Process data
Write data to B from your app
Then you have singe read single write and is simple.
You can not gain the result of INSERT INTO as Result set as this is INSERT statement
Sadly, I do not think that this is possible. What you are trying to achieve are two distinct operations i.e. an INSERT and a SELECT. However you cut it you are still going have to do at least one INSERT and one SELECT.
use this for two database
INSERT INTO Database2 (field1,field2,field3){
SELECT * FROM Database1;);
Both the database have the same field name.
I have this table in oracle and i need to retrieve two columns from the table desc_data
eg:
select ticket_id, date_logged from desc_data;
I would have around 10,000 records in this table, so if I do this operation from java and perform some operations in java by putting these values in a list and then based on some conditions filter data and insert back into some other table, would it be possible and if it's possible would it be an overhead?
I think better to use a stored procedure in database and just call it from java. But what you consider is a possible solution too.
It depends on what type of filtering you wish to do on your 10000 records. If the filtering is simple, such as filtering the records in a date range, then you can achieve that just using SQL. If your processing is more complex, then you could also use an stored procedure. As you are running on Oracle these can be written in Java. See here for an example.