Presentation is loading. Please wait.

Presentation is loading. Please wait.

JDBC Java Database Connectivity. What is an RDBMS? Relational database management system. There are other kinds of DBMS. Access is a GUI on a JET RBDMS.

Similar presentations


Presentation on theme: "JDBC Java Database Connectivity. What is an RDBMS? Relational database management system. There are other kinds of DBMS. Access is a GUI on a JET RBDMS."— Presentation transcript:

1 JDBC Java Database Connectivity

2 What is an RDBMS? Relational database management system. There are other kinds of DBMS. Access is a GUI on a JET RBDMS backend. Language for RBMS - > SQL

3 SQL Structured Query Language There are many standards for SQL SQL92, SQL 89, SQL99, Some commands exists for all the standards. Some commands exists only for specific products

4 Why do I need JDBC? Connects to a RDBMS RDBMS Neutral Standard API (portable) Allows for transmission of SQL Can help to process results.

5 Using JDBC and Tiers Java program calls JDBC methods These methods transmit SQL statements The RDBMS responds, via the JDBC methods This is a 2 Tier system.

6 SQL Is NOT OOP language (yet) able to store instances of classes able to store blobs (unformatted sequences of bytes)

7 RBMS is good for storing data searching data non-programmer updates of data.

8 JDBC+RDBMS=2 tier computing Client + server = 2 tier computing. JDBC does connections, query and result processing from the RDBMS. JDBC uses SQL.

9 Process 1.Connect to DBMS 2.Instance SQL Statement 3.Execute SQL statement 4.Process SQL results 5.close connection to DBMS

10 3 tier system - distributed computing client web server rdbms cgi html browser w/o java jdbc jdbc results

11 4 tier system - distributed computing client web server rdbms cgi html browser w/o java jdbc jdbc results b-logic

12 Jdbc driver ideas JDBC needs to work with many DBMS Oracle mySql JET DB2 SQLServer, etc....

13 Mapping to a DSN... JDBC with ODBC driver is called JDBC/ODBC (microsoft method). connect using a protocol and subprotocol

14 How do I formulate a connect URL? String url =“jdbc:dbnet://show.docjava.com:356/addre sses” jdbc – primary protocol dbnet – sub protocol show.docjava.com – FQDN 356 – standard port for RDBMS services

15 What Packages do I need? import java.sql.*;

16 The format of the url string is vendor specific String url = “jdbc:dbnet://localhost:356/Books”; where dbnet is an example of a subprotocol, and //localhost:356/Books is an example of a subname. The DriverManager class can also take an optional user name and password. For example: Connection c = DriverManager.getConnection(url, “userid”, “password”);

17 Setting up a RDBMS How to set up your RDBMS How to get drivers for JDBC How to load the drivers How to set up a select few IDEs for programming

18 data source name (DSN) The DSN can be set using one of several techniques. Under Windows, double-click the ODBC Data Sources (32bit) control panel.

19 Using Appendix H ODBC Data Source Administrator is shown upon opening the ODBC Data Sources control panel. Select the MS Access Database driver and click Add...

20 Adding a database

21 Create a new data source

22 Set up

23 Add the DSN

24 MDB Files look like:

25 Mapping the DSN File:

26 Using odbc to mysql http://www.mysql.com/downloads/api- myodbc.html Access to mysql via odbc driver

27 Configuration

28 Accessing and ODBC database

29 Select your Data Source

30 Select your tables

31 Click on the tables

32 Setting up mysql >mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 to server version: 3.23.22-beta-log Type 'help' for help. mysql> use test Database changed

33 Make a table mysql> create table User ( UserId varchar(10), Password varchar(10)); Query OK, 0 rows affected (0.06 sec) To create a more more complex table (for example a phone book) use: mysql> create table phonelist (firstname varchar(20),lastname varchar(20), address1 varchar(255), address2 varchar(255), phone1 varchar(50), phone2 varchar(50), phone3 varchar(50)); Query OK, 0 rows affected (0.04 sec) mysql> show tables;

34 Get a driver.

35 grant access to the user mysql> show grants ; grant create on *.* to guest; Query OK, 0 rows affected (0.08 sec) mysql> use test; Database changed mysql> create table flatfile (message char(255)); Query OK, 0 rows affected (0.02 sec)

36 Loading a table Use the load command to import data from a text file. For example: mysql> LOAD DATA LOCAL INFILE “c:\lyon\j4p\src\addbk\JAddressBook\foo.cs v" INTO TABLE phonelist FIELDS TERMINATED BY '\t' (name, kind, createdDate, modifiedDate);

37 Selecting records select * from flatfile;

38 class DataBaseMetaData is obtained automatically by the SqlBean Class.forName(driver); c = DriverManager.getConnection(url,userId,password); dbmd = c.getMetaData(); catalogName = c.getCatalog(); isReadOnly = c.isReadOnly(); usesLocalFiles = dbmd.usesLocalFiles(); driverName = dbmd.getDriverName();

39 For Next Week Make the addressbook program index work so that selecting a letter will display the index so that it starts from that letter. Use the first letter that appears in the name field. If you select ‘I’ but there are no records that start with ‘I’ go to the record preceding where I should be.. For ‘a’ go to the beginning.

40 Implements the CSV features Using your jtable, import from text files via a delimiter panel. Using the delimiter panel, export your text files.


Download ppt "JDBC Java Database Connectivity. What is an RDBMS? Relational database management system. There are other kinds of DBMS. Access is a GUI on a JET RBDMS."

Similar presentations


Ads by Google