1 / 6

Advanced OOP MCS-3 OOP BSCS-3 Lecture # 11

Advanced OOP MCS-3 OOP BSCS-3 Lecture # 11. Connect. Query. Process Results. Close. Database Connectivity in Java. JDBC Programming Steps. JDBC Programming JDBC (Java Database Connectivity) is the specification of a Java API that allows Java programs to access DBMSs.

naasir
Download Presentation

Advanced OOP MCS-3 OOP BSCS-3 Lecture # 11

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced OOP MCS-3 OOP BSCS-3Lecture # 11

  2. Connect Query Process Results Close Database Connectivity in Java JDBC Programming Steps JDBC Programming • JDBC (Java Database Connectivity) is the specification of a Java API that allows Java programs to access DBMSs. • The JDBC API consists of a set of interfaces and classes written in the Java programming language. • Using these standard interfaces and classes, programmers can write applications that connect to databases, send queries written in structured query language (SQL), and process the results. Register • Register the driver • Create a connection to the • database • Create a statement • Query the database • Get a result set • Assign results to Java variables • Close the result set • Close the statement • Close the connection

  3. Database Connectivity in Java STEP 1: Register • A JDBC driver is needed to connect to a database. • Registering a driver requires the class name of the driver. Example)JDBC-ODBC: sun.jdbc.odbc.JdbcOdbcDriver Oracle driver: oracle.jdbc.driver.OracleDriver MySQL:com.mysql.jdbc.Driver • Loading the driver class • Class.forName(String); • Defined in java.lang.Class(no need to import) • It is possible to load several drivers. • The class DriverManagermanages the loaded driver(s).

  4. Sub-protocol: identifies a database driver Sub-protocol: identifies a database driver Subname: indicates the location and name of the database to be accessed. Syntax is driver specific. DSN name should be used. Subname: indicates the location and name of the database to be accessed. Syntax is driver specific Protocol: JDBC is the only protocol in JDBC Protocol: JDBC is the only protocol in JDBC Database Connectivity in Java STEP 2: Connect • JDBC URL for a database • Identifies the database to be connected • Consists of three-parts: • <protocol>:<subprotocol>:<subname> • The DriverManager allows you to connect to a database using the specified JDBC driver, database location, database name, username and password. • It returns a Connection object which can then be used to communicate with the database. java.sql.DriverManager • Connection getConnection(String) //url • Connection getConnection(String, String, String) //url, username, password

  5. Database Connectivity in Java DSN • A Data Source Name (DSN) is the logical name that is used by Open Database Connectivity (ODBC) to refer to the driver and other information that is required to access data.  Create a System DSN in Windows • From Control Panel, open Administrative Tools, and then open Data Sources(ODBC). • Click the System DSN tab, and then click Add. • Click the database driver that corresponds with the database type to which you are connecting, and then click Finish. • Type the data source name. Make sure that you choose a name that you can remember. You will need to use this name later. • Click Select. • Click the correct database, and then click OK. • Click OK, and then click OK.

  6. Good Luck ! ☻. . .

More Related