How to insert ignore with 100+ input valuesCan Hibernate work with MySQL's “ON DUPLICATE KEY UPDATE” syntax?Batch insert using Native SQL in HibernateIs Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?How can I prevent SQL injection in PHP?Sort a Map<Key, Value> by valuesHow do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?“INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”How to get an enum value from a string value in Java?How do I determine whether an array contains a particular value in Java?How do I convert a String to an int in Java?
Why can't I see bouncing of a switch on an oscilloscope?
Maximum likelihood parameters deviate from posterior distributions
What defenses are there against being summoned by the Gate spell?
When a company launches a new product do they "come out" with a new product or do they "come up" with a new product?
Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?
Today is the Center
Can you really stack all of this on an Opportunity Attack?
Intersection point of 2 lines defined by 2 points each
Codimension of non-flat locus
Has there ever been an airliner design involving reducing generator load by installing solar panels?
A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?
Malcev's paper "On a class of homogeneous spaces" in English
How does quantile regression compare to logistic regression with the variable split at the quantile?
Why is 150k or 200k jobs considered good when there's 300k+ births a month?
Is it unprofessional to ask if a job posting on GlassDoor is real?
Why does Kotter return in Welcome Back Kotter?
How much RAM could one put in a typical 80386 setup?
Is it possible to run Internet Explorer on OS X El Capitan?
NMaximize is not converging to a solution
dbcc cleantable batch size explanation
If human space travel is limited by the G force vulnerability, is there a way to counter G forces?
Definite integral giving negative value as a result?
What would happen to a modern skyscraper if it rains micro blackholes?
High voltage LED indicator 40-1000 VDC without additional power supply
How to insert ignore with 100+ input values
Can Hibernate work with MySQL's “ON DUPLICATE KEY UPDATE” syntax?Batch insert using Native SQL in HibernateIs Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?How can I prevent SQL injection in PHP?Sort a Map<Key, Value> by valuesHow do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?“INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”How to get an enum value from a string value in Java?How do I determine whether an array contains a particular value in Java?How do I convert a String to an int in Java?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
i'm learning Java hibernate,
found an example of "insert ignore",
Query query = getSession().createSQLQuery("INSERT IGNORE INTO TABLA (ID, VAR) VALUES (:id, :var)");
UUID id = UUID.randomUUID();
query.setParameter("id", id);
String var = "abcde";
query.setParameter("var", var);
query.executeUpdate();
This will "insert ignore" 1 entry.
I may have 100+ var as input, but only 1 or 2 will not be in the existing table, i don't know which ones.
If i set Parameters of 100 of values with a loop, it may work. But is there a better may ? given i may just need to insert 1 or 2 of them really.
Or i should ask this: given a list of 100 var string, find out the a few not in existing table, without using loop.
java mysql hibernate
add a comment |
i'm learning Java hibernate,
found an example of "insert ignore",
Query query = getSession().createSQLQuery("INSERT IGNORE INTO TABLA (ID, VAR) VALUES (:id, :var)");
UUID id = UUID.randomUUID();
query.setParameter("id", id);
String var = "abcde";
query.setParameter("var", var);
query.executeUpdate();
This will "insert ignore" 1 entry.
I may have 100+ var as input, but only 1 or 2 will not be in the existing table, i don't know which ones.
If i set Parameters of 100 of values with a loop, it may work. But is there a better may ? given i may just need to insert 1 or 2 of them really.
Or i should ask this: given a list of 100 var string, find out the a few not in existing table, without using loop.
java mysql hibernate
1
Take a look at: stackoverflow.com/a/25480573/5066625
– Miroslav Glamuzina
Mar 9 at 1:07
Just to be clear, you use the loop to build a single query, right? You don't execute 100 queries?
– Strawberry
Mar 9 at 8:50
@Strawberry yes i expect 1 query if it's possible, how to do it is my question
– user3552178
Mar 9 at 21:02
add a comment |
i'm learning Java hibernate,
found an example of "insert ignore",
Query query = getSession().createSQLQuery("INSERT IGNORE INTO TABLA (ID, VAR) VALUES (:id, :var)");
UUID id = UUID.randomUUID();
query.setParameter("id", id);
String var = "abcde";
query.setParameter("var", var);
query.executeUpdate();
This will "insert ignore" 1 entry.
I may have 100+ var as input, but only 1 or 2 will not be in the existing table, i don't know which ones.
If i set Parameters of 100 of values with a loop, it may work. But is there a better may ? given i may just need to insert 1 or 2 of them really.
Or i should ask this: given a list of 100 var string, find out the a few not in existing table, without using loop.
java mysql hibernate
i'm learning Java hibernate,
found an example of "insert ignore",
Query query = getSession().createSQLQuery("INSERT IGNORE INTO TABLA (ID, VAR) VALUES (:id, :var)");
UUID id = UUID.randomUUID();
query.setParameter("id", id);
String var = "abcde";
query.setParameter("var", var);
query.executeUpdate();
This will "insert ignore" 1 entry.
I may have 100+ var as input, but only 1 or 2 will not be in the existing table, i don't know which ones.
If i set Parameters of 100 of values with a loop, it may work. But is there a better may ? given i may just need to insert 1 or 2 of them really.
Or i should ask this: given a list of 100 var string, find out the a few not in existing table, without using loop.
java mysql hibernate
java mysql hibernate
asked Mar 9 at 1:00
user3552178user3552178
4651817
4651817
1
Take a look at: stackoverflow.com/a/25480573/5066625
– Miroslav Glamuzina
Mar 9 at 1:07
Just to be clear, you use the loop to build a single query, right? You don't execute 100 queries?
– Strawberry
Mar 9 at 8:50
@Strawberry yes i expect 1 query if it's possible, how to do it is my question
– user3552178
Mar 9 at 21:02
add a comment |
1
Take a look at: stackoverflow.com/a/25480573/5066625
– Miroslav Glamuzina
Mar 9 at 1:07
Just to be clear, you use the loop to build a single query, right? You don't execute 100 queries?
– Strawberry
Mar 9 at 8:50
@Strawberry yes i expect 1 query if it's possible, how to do it is my question
– user3552178
Mar 9 at 21:02
1
1
Take a look at: stackoverflow.com/a/25480573/5066625
– Miroslav Glamuzina
Mar 9 at 1:07
Take a look at: stackoverflow.com/a/25480573/5066625
– Miroslav Glamuzina
Mar 9 at 1:07
Just to be clear, you use the loop to build a single query, right? You don't execute 100 queries?
– Strawberry
Mar 9 at 8:50
Just to be clear, you use the loop to build a single query, right? You don't execute 100 queries?
– Strawberry
Mar 9 at 8:50
@Strawberry yes i expect 1 query if it's possible, how to do it is my question
– user3552178
Mar 9 at 21:02
@Strawberry yes i expect 1 query if it's possible, how to do it is my question
– user3552178
Mar 9 at 21:02
add a comment |
1 Answer
1
active
oldest
votes
You could use the MySQL ON DUPLICATE KEY UPDATE
feature.
For example:
INSERT INTO TABLA (ID, VAR) VALUES (1, 1), (2, 2), ... ON DUPLICATE KEY UPDATE ID=ID;
I'm not familiar with java or hibernate, hence my answer being a raw query. If you need help figuring out the exact syntax, this question might be a good resource for it.
Also, generally speaking, ON DUPLICATE KEY UPDATE
is much safer than INSERT IGNORE
because the latter will ignore all errors, while the former will only ignore duplicate inserts.
Hope this helps!
my concern is, the INSERT string is so long if i have 100 vars and uuid, won't this hit some max string length ?
– user3552178
Mar 9 at 2:45
I don't think so. I run a similar query that is roughly 13000 bytes long, so I don't think it will matter.
– Jane
Mar 9 at 3:03
I think I'd try to find a way to use the values option with this solution
– Strawberry
Mar 10 at 2:17
@Strawberry what do you mean?
– Jane
Mar 10 at 3:06
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55072974%2fhow-to-insert-ignore-with-100-input-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could use the MySQL ON DUPLICATE KEY UPDATE
feature.
For example:
INSERT INTO TABLA (ID, VAR) VALUES (1, 1), (2, 2), ... ON DUPLICATE KEY UPDATE ID=ID;
I'm not familiar with java or hibernate, hence my answer being a raw query. If you need help figuring out the exact syntax, this question might be a good resource for it.
Also, generally speaking, ON DUPLICATE KEY UPDATE
is much safer than INSERT IGNORE
because the latter will ignore all errors, while the former will only ignore duplicate inserts.
Hope this helps!
my concern is, the INSERT string is so long if i have 100 vars and uuid, won't this hit some max string length ?
– user3552178
Mar 9 at 2:45
I don't think so. I run a similar query that is roughly 13000 bytes long, so I don't think it will matter.
– Jane
Mar 9 at 3:03
I think I'd try to find a way to use the values option with this solution
– Strawberry
Mar 10 at 2:17
@Strawberry what do you mean?
– Jane
Mar 10 at 3:06
add a comment |
You could use the MySQL ON DUPLICATE KEY UPDATE
feature.
For example:
INSERT INTO TABLA (ID, VAR) VALUES (1, 1), (2, 2), ... ON DUPLICATE KEY UPDATE ID=ID;
I'm not familiar with java or hibernate, hence my answer being a raw query. If you need help figuring out the exact syntax, this question might be a good resource for it.
Also, generally speaking, ON DUPLICATE KEY UPDATE
is much safer than INSERT IGNORE
because the latter will ignore all errors, while the former will only ignore duplicate inserts.
Hope this helps!
my concern is, the INSERT string is so long if i have 100 vars and uuid, won't this hit some max string length ?
– user3552178
Mar 9 at 2:45
I don't think so. I run a similar query that is roughly 13000 bytes long, so I don't think it will matter.
– Jane
Mar 9 at 3:03
I think I'd try to find a way to use the values option with this solution
– Strawberry
Mar 10 at 2:17
@Strawberry what do you mean?
– Jane
Mar 10 at 3:06
add a comment |
You could use the MySQL ON DUPLICATE KEY UPDATE
feature.
For example:
INSERT INTO TABLA (ID, VAR) VALUES (1, 1), (2, 2), ... ON DUPLICATE KEY UPDATE ID=ID;
I'm not familiar with java or hibernate, hence my answer being a raw query. If you need help figuring out the exact syntax, this question might be a good resource for it.
Also, generally speaking, ON DUPLICATE KEY UPDATE
is much safer than INSERT IGNORE
because the latter will ignore all errors, while the former will only ignore duplicate inserts.
Hope this helps!
You could use the MySQL ON DUPLICATE KEY UPDATE
feature.
For example:
INSERT INTO TABLA (ID, VAR) VALUES (1, 1), (2, 2), ... ON DUPLICATE KEY UPDATE ID=ID;
I'm not familiar with java or hibernate, hence my answer being a raw query. If you need help figuring out the exact syntax, this question might be a good resource for it.
Also, generally speaking, ON DUPLICATE KEY UPDATE
is much safer than INSERT IGNORE
because the latter will ignore all errors, while the former will only ignore duplicate inserts.
Hope this helps!
answered Mar 9 at 2:22
JaneJane
1,1981518
1,1981518
my concern is, the INSERT string is so long if i have 100 vars and uuid, won't this hit some max string length ?
– user3552178
Mar 9 at 2:45
I don't think so. I run a similar query that is roughly 13000 bytes long, so I don't think it will matter.
– Jane
Mar 9 at 3:03
I think I'd try to find a way to use the values option with this solution
– Strawberry
Mar 10 at 2:17
@Strawberry what do you mean?
– Jane
Mar 10 at 3:06
add a comment |
my concern is, the INSERT string is so long if i have 100 vars and uuid, won't this hit some max string length ?
– user3552178
Mar 9 at 2:45
I don't think so. I run a similar query that is roughly 13000 bytes long, so I don't think it will matter.
– Jane
Mar 9 at 3:03
I think I'd try to find a way to use the values option with this solution
– Strawberry
Mar 10 at 2:17
@Strawberry what do you mean?
– Jane
Mar 10 at 3:06
my concern is, the INSERT string is so long if i have 100 vars and uuid, won't this hit some max string length ?
– user3552178
Mar 9 at 2:45
my concern is, the INSERT string is so long if i have 100 vars and uuid, won't this hit some max string length ?
– user3552178
Mar 9 at 2:45
I don't think so. I run a similar query that is roughly 13000 bytes long, so I don't think it will matter.
– Jane
Mar 9 at 3:03
I don't think so. I run a similar query that is roughly 13000 bytes long, so I don't think it will matter.
– Jane
Mar 9 at 3:03
I think I'd try to find a way to use the values option with this solution
– Strawberry
Mar 10 at 2:17
I think I'd try to find a way to use the values option with this solution
– Strawberry
Mar 10 at 2:17
@Strawberry what do you mean?
– Jane
Mar 10 at 3:06
@Strawberry what do you mean?
– Jane
Mar 10 at 3:06
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55072974%2fhow-to-insert-ignore-with-100-input-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Take a look at: stackoverflow.com/a/25480573/5066625
– Miroslav Glamuzina
Mar 9 at 1:07
Just to be clear, you use the loop to build a single query, right? You don't execute 100 queries?
– Strawberry
Mar 9 at 8:50
@Strawberry yes i expect 1 query if it's possible, how to do it is my question
– user3552178
Mar 9 at 21:02