473,385 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

static/dynamic/embedded SQL distinctions

I want to distinguish between static SQL, dynamic SQL, and embedded
SQL, but couldn't find too much useful resources in the web.

For example, if we put SQL statements (SELECT, INSERT, UPDATE, etc...)
inside an application (e.g. Java application, VB application, etc...),
do we consider those SQL statements as static SQL? or embedded SQL?

How about dynamic SQL? any practical examples?

Please advise. thanks!!

Aug 22 '05 #1
4 4761
jr********@hotmail.com wrote:
I want to distinguish between static SQL, dynamic SQL, and embedded
SQL, but couldn't find too much useful resources in the web.

For example, if we put SQL statements (SELECT, INSERT, UPDATE, etc...)
inside an application (e.g. Java application, VB application, etc...),
do we consider those SQL statements as static SQL? or embedded SQL?

How about dynamic SQL? any practical examples?

Please advise. thanks!!


My take on that would be...

static SQL
==========
Hard-coded SQL statements in code, e.g.:
java.sql.ResultSet rs = stmt.executeQuery(
"SELECT colA, colB FROM tableA"
) ;

while(rs.next()) {
System.out.println("colA: " + rs.getString(1)) ;
System.out.println("colB: " + rs.getString(2)) ;
}

dynamic SQL
===========
Building the SQL string according to passed-in parameters, e.g.:
public PreparedStatement getStmt(Connection con, String sCity) {
PreparedStatement pstmt = con.prepareStatement(
"SELECT colA, colB from tableA"
+ (null==sCity ? "" : " WHERE city=?")
) ;
if(null!=sCity) {
pstmt.setString(1, sCity) ;
}
return pstmt ;
}

java.sql.ResultSet rs = getStmt(con, "London").executeQuery() ;
while(rs.next()) {
System.out.println("colA: " + rs.getString(1)) ;
System.out.println("colB: " + rs.getString(2)) ;
}

As for embedded SQL, I've always thought of that as putting SQL
statements in code (in a language-neutral way) and using a preprocessor
of some sort to generate code in place, e.g what Pro*C does for Oracle:
http://www-db.stanford.edu/~ullman/f...e/or-proc.html

Aug 22 '05 #2
Dynamic SQL is made up on the fly by a procedure or end user as a
string contianing SQL statements. The ANSI Standards have PREPARE and
EXECUTE statements for this. Microsoft and other vendors will do it
differently, but it is the same idea. Like having Query Analyzer in
your program -- and just as dangerous.

Embedded SQL is placed inside a host program, not built on the fly.
Its statements begin with the keywords "EXEC SQL <sql code>" . A
preprocessor converts these statements into API or CLI calls
appropriate for the host language.

Static SQL is simply native SQL code. Since SQL has to exist in a host
program to talk to the outside world, it will be embedded somewhere.
Or it can be part of a trigger, stored procedure, etc.

You missed the SQL/CLI, ODBC, JDBC, etc. which are call level
interfaces from host languages to an SQL database.
..

Aug 22 '05 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

jr********@hotmail.com wrote:
I want to distinguish between static SQL, dynamic SQL, and embedded
SQL, but couldn't find too much useful resources in the web.

For example, if we put SQL statements (SELECT, INSERT, UPDATE, etc...)
inside an application (e.g. Java application, VB application, etc...),
do we consider those SQL statements as static SQL? or embedded SQL?


OK, here we go:

embedded SQL - Actual SQL code embedded into your Java code and converted to
Java code by a preprocessor and then compiled normally.

static SQL - SQL that is handled normally. It doesn't change at runtime.
It is a constant string literal.

dynamic SQL - SQL that may change at runtime. For instance the where
clause on a SQL statement may be dependent on factors
not known at compile time.

The difference between static and dynamic SQL has to do with when the plan
for database access is determined. With static SQL the plan is determined
before your program ever runs (or at least could be). This means that the
database doesn't have to figure out how to find the data you are interested
in at runtime. It also means that if the database statistics change
radically the plan used by your query may become out of date.

The plan used to execute dynamic SQL statements is determined at runtime.
This means that knowledge only available at runtime may be used to form the
SQL statement. It also means that the plan will be up to date with the
current database statistics. Unfortunately the database will have to do
extra work at runtime to determine what the plan should be.

These concepts have little to do with Java. Databases accessed using other
languages run into the same set of tradeoffs.

If you would like sample code you might want to look up SQLJ at Google.
There is plenty of source code on the web.

- --
Kenneth P. Turvey <kt@squeakydolphin.com>

Currently seeking employment as a Java developer in the St. Louis area.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFDCjmw3naBnF2rJNURAhnqAJ9qkxTWvaFndj0TZmP5RA sO/CBi2QCeIHgD
oAi6MAXrNur7+P+0PBLVj+w=
=oPfU
-----END PGP SIGNATURE-----
Aug 22 '05 #4
On Mon, 22 Aug 2005 12:02:02 -0700, jrefactors interested us by writing:
I want to distinguish between static SQL, dynamic SQL, and embedded
SQL, but couldn't find too much useful resources in the web.


LOL ... Did you check the Oracle documentation at http://docs.oracle.com

From the Oracle9i doc set:

Embedded SQL ... from the Concepts manual

http://download-west.oracle.com/docs...sql.htm#i18523

Dynamic SQL and Static SQL from the "Application Developer's Guide -
Fundamentals" in the Chapter 6, titled "What Is Dynamic SQL?"

http://download-west.oracle.com/docs...dy.htm#1006233

--
Hans Forbrich
Canada-wide Oracle training and consulting
mailto: Fuzzy.GreyBeard_at_gmail.com
*** I no longer assist with top-posted newsgroup queries ***

Aug 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dumitru Sipos | last post by:
Hello everybody! is there possible to have a function that is both static and virtual? Dumi.
15
by: rwf_20 | last post by:
I just wanted to throw this up here in case anyone smarter than me has a suggestion/workaround: Problem: I have a classic producer/consumer system which accepts 'commands' from a socket and...
2
by: Dominik Stadler | last post by:
Hi, We are trying to migrate an application from Oracle to DB2. In Oracle we used some functionality to attach a dynamic SQL - connection to the static SQL Connection in order to perform SQL in...
13
by: Krivenok Dmitry | last post by:
Hello all! Perhaps the most important feature of dynamic polymorphism is ability to handle heterogeneous collections of objects. ("C++ Templates: The Complete Guide" by David Vandevoorde and...
5
by: pittendrigh | last post by:
There must be millions of dynamically generated html pages out there now, built by on-the-fly php code (and jsp, perl cgi, asp, etc). Programatic page generation is transparently useful. But...
24
by: Ken | last post by:
In C programming, I want to know in what situations we should use static memory allocation instead of dynamic memory allocation. My understanding is that static memory allocation like using array...
7
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
20
by: Nickolai Leschov | last post by:
Hello all, I am programming an embedded controller that has a 'C' library for using its system functions (I/O, timers, all the specific devices). The supplied library has .LIB and .H files. ...
6
by: =?ISO-8859-1?Q?Tim_B=FCthe?= | last post by:
Hi, we are building a Java webapplication using JSF, running on websphere, querying a DB2 9 on Suse Enterprise 10. The app uses JDBC and PreparedStatements only (aka dynamic SQL). Every night,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.