I use jdbc to use Oracle database.
Does using jdbc means by changing the driver I can use
any database? irrespective of whether that database system
has the same sql syntax or not? Should i change my sql
statements that I use in java, to suit the syntax of the
db system? Or the same syntax should work - ie., the driver
will take care and convert to the required syntax?
if you use standard jdbc defined by Sun your code is going to be portable, no matter what database you will be using - your database needs to be relational, of course, then your sql will be portable too.
For each database, you must have a driver. For example, to use jdbc with oracle with must have oracle jdbc drivers (classes12.zip). You also can use oracle extention for jdbc, then your code will need to change if you change database.
Is the code portable even if the underlying database's
sql syntax is different? ie., will the jdbc driver convert
the sql into its propreitary syntax?
Particularly I am concerned about the SEQUENCE syntax.
select CUSTOMER_SEQ.NEXTVAL from DUAL
doesnt this assume the presence of a table called "DUAL"
in the database? is this oracle specific or not?
No, your code will not be portable. You will not get an error on the Java level but, as you already expect it, on the database level when you ll try to run you statement on the DB.
JDBC is a standard API for connecting to databases. This means that you can connect to any database and process SQL statements using the same programatic logic. However, it does not mean that any SQL statement will work with each engine. It is up to you to make sure you have either SQL that will work with all engines, or you have an application that can be customised for all eninges.
Click Here to Expand Forum to Full Width