Java – what do I mean when I say prepared statements are precompiled?

I use MySQL in Java I don't have a good understanding of Preparedstatement

What does compilation mean?

Solution

When you use a pre prepared statement (i.e. a pre compiled statement), once the DB obtains the statement, it will compile it and cache it so that it can use the last compiled statement to call the same statement continuously So it becomes a precompile of successive calls

You usually use prepared statements with bound variables, which you can provide at run time Now, for what happens in a continuous preexecution statement, you can provide variables that are different from previous calls. From the perspective of DB, it does not have to compile statements every time, but only inserts binding variables during rum So it gets faster

Other benefits of preparing a presentation are: –

1) Prevent SQL injection attacks

2) Faster sequential invocation of the same statement

How does this work-

>Precompiling is done by the database Some simpler databases do not precompile statements at all Others may precompile it on the preparestatement call, while others may perform this operation when the statement is called for the first time, taking the parameter values into account when compiling (creating plan) statements. > Databases that execute precompiled statements usually cache them, so it is likely that ps1.0 will not be compiled again Some JDBC drivers (such as Oracle) even cache preprocessing statements, so they don't actually close ps.close() when they call it. > Databases usually cache statements until something evicts them from the cache

For more information, please browse this wiki link

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>