Pages

Subscribe:

Ads 468x60px

Tuesday, November 1, 2011

JDBC URL

True to the nature of the internet, JDBC identifies a database with an URL. The URL’s form is as follows:
jdbc:<subprotocol>:<subname related to the DBMS/Protocol>
For database on the Internet or Intranet, the subname can contain the Net URL // hostname:port/. The <subprotocol> can be any name that a database understands. The odbc subprotocol name is reserved for ODBC-style data sources. A normal ODBC database JDBC URL looks like the following:
jdbc:odbc:<ODBC DSN>;user=<username>;pw=<password>
To handle data from a database, a Java program follows these general steps. First, the program calls the getConnection() method to get the Connection object. Then it creates the Statement object and prepares a SQL statement.
A SQL statement can be executed immediately (Statement Object), can be a compiled statement (PreparedStatement object), or can be call to a stored procedure (CallableStatement object). When the method executeQuery() is executed, a ResultSet object is returned. SQL statements such as update or delete will not return a ResultSet. For such statements, the executeUpdate() method is used. The executeUpdate () method returns an integer that denotes the number of rows affected by the SQL statement.
The ResultSet contains rows of data that are parsed using the next() method. In case of a transaction processing application, methods such as rollback() and commit() can be used either to undo the changes made by the SQL statements or permanently affect the changes made by the SQL statements.

JDBC class hierarchy and a JDBC API flow:

No comments:

Post a Comment