Presentation is loading. Please wait.

Presentation is loading. Please wait.

JDBC Database Management Database connectivity

Similar presentations


Presentation on theme: "JDBC Database Management Database connectivity"— Presentation transcript:

1 JDBC Database Management Database connectivity
Installing the ODBC driver Querying a database Adding, modifying and deleting records

2 Database Management A database is a collection of related information and a DBMS is a software that provides you with a mechanism to retrieve, modify and add to the database. There are many DBMS/RDBMS products available. eg- MS-Access, MS-SQL Server, Oracle, Sybase, Informix, Progress and Ingres.

3 Database Connectivity
Any application to communicate with the database, it needs to have the following information: The RDBMS/DBMS product using which database is created. The location of the database. The name of the database. Here you could able to work with only one kind of database and difficult to code. The above problem is solved by Microsoft’s standard for communication using Open Database Connectivity(ODBC). Queries For Data Application MS-Access Responds to a Query MS-SQL

4 ODBC Application Programming Interface(API)
ODBC API is a set of library routines that enables your program to access a variety of databases. All you need to install a DBMS- specific ODBC driver. MS-Access Application ODBC Driver Manager Access Driver SQL Driver MS-SQL ODBC Application Architecture

5 JDBC API JDBC API There are several categories of JDBC drivers available. JDBC-ODBC bridge+ODBC driver Native API partly Java driver. JDBC-Net pure Java driver Native protocol pure java driver. MS-Access Application JDBC Driver Manager JDBC- ODBC Bridge Driver Access Driver SQL Driver MS-SQL JDBC Application Architecture

6 JDBC provides a standard library for accessing relational databases -API standardizes Way to establish connection to database Approach to initiating queries Method to create stored (parameterized)queries The data structure of query result(table) Determine the number of columns Looking up metadata, etc., -API does not standardize SQL syntax JDBC is not embedded SQL -JDBC class located in java.sql package

7 JDBC consists of two parts : -JDBC API, a purely
Java-based API -JDBC Driver Manager, which communicates with --Vendor-specific drivers that perform the real communication with the database. --Point : translation to vendor format is performed on the client -No changes needed to server -Driver needed on client

8

9 INSTALLING THE ODBC DRIVER
Steps for Configuring the ODBC Driver Creating DSN(Data Source Name) Click on the ODBC Data Source icon in the control panel. Click on the add button in the ODBC Data Source Administrator dialog box.

10 3. Select the SQL Server option from the list and click on Finish in the Create New Data Source. Dialog box.

11 4. Type a name for the data source in the Name text box, specify the name of the server you want to connect to, and then, click on the Next button.

12 5. Select the with SQL Server authentication using login ID and password entered by the user option from the Microsoft SQL Server DSN Configuration dialog box and then click on the Next button.

13 6. Select the database that you want to use and click on the Next button.

14 7. Click on the Finish button.

15 8. Click on Test Data Source to check for proper connectivity with the database and then click on OK to end the ODBC set up. Click on OK

16

17

18

19

20

21 Querying A DataBase After Creating DSN load a driver
Loading a Driver : we should load the driver into JVM before requesting for a connection. the forName() method from the Class is loading a class into the memory. Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); Connecting to a Database : The Connection Object represents a connection with a database. Connection con=DriverManager.getConnection(“jdbc.odbc.<dsn>”, ”<username>”,”<pwd>”);

22 DatabaseMetaData : Contains the details about the Database.
String getDriverName() String getDatabaseProductname() String getDatabaseProductVersion() Statement Object : For executing sql statements against the database Statement stat=con.createStatement(); executeQuery() simple select query and returns single ResultSet object. executeUpdate() executes the SQl INSERT,UPDATE and DELETE statements. execute() executes a SQL statement that may return multiple results.

23 Preparedstatement Object : it contains a set of methods that you can use for sending queries with INPUT parameters. stat=con.preparedStatement(“select 8 from employees where extension=?”); CallableStatement Object : it contains functionality for calling a stored procedure. You can handle both INPUT and OUTPUT parameters. ResultSet Object : it contains the collection of selected from the database. boolean next() boolean previous() boolean first() boolean Last() String getString(String fieldname) int getInt(int fieldno)


Download ppt "JDBC Database Management Database connectivity"

Similar presentations


Ads by Google