JDBC
JDBC, Java DataBase Connectivity (connection to databases in Java) - the industry standard for the interaction of Java applications with various DBMS. Implemented as the java.sql package included with Java SE.
JDBC is based on the concept of drivers that allow you to get a connection to a database at a specially described URL. When loaded, the driver registers itself in the system and is then automatically called when the program requires a URL containing the protocol for which this driver is responsible.
Benefits of using JDBC
The advantages of JDBC are:
- Ease of development: the developer may not know the specifics of the database with which he works;
- The code practically does not change if the company moves to another database (the number of changes depends solely on the differences between the SQL dialects);
- There is no need to additionally install the client program;
- Any database can be connected via an easily descriptive URL.
JDBC URL
JDBC URL consists of:
- <protocol>: - always jdbc:
- <subprotocol>: is the driver name or the name of the database connection mechanism. A subprotocol can be supported by one or more drivers. An example of a subprotocol on the surface is "odbc" for URLs denoting the name of an ODBC data source. If you want to use a naming service (ie, the database name in the JDBC URL will not be a valid database name), then the naming service can be the subprotocol.
- <subname> is the database identifier. The meaning of the sub-name can vary depending on the subprotocol, and can also have a sub-sub-name with the syntax defined by the driver developer. The purpose of a subname is to provide all the information needed to find the database. For example, if the database is on the Internet, then the JDBC URL subname must include a network address that obeys the following conventions: //<hostname>:<port>/<subsubname>
Example JDBC URL for connecting to MySQL database "Test" located at localhost and listening for connections on port 3306: jdbc:mysql://localhost:3306/Test
Read also:
- Data integrity constraints in SQL
- IN, BETWEEN, LIKE operators in SQL
- Stored Procedure, Triggers, Cursor
Comments
Post a Comment