0% found this document useful (0 votes)
88 views9 pages

What Is JDBC?

JDBC is a set of Java APIs that allow Java programs to connect to databases. It includes interfaces and classes for connecting to a database via a JDBC driver, executing SQL statements, and processing the results. Common JDBC drivers support connecting to databases like Oracle, MySQL, SQL Server, and more. The Connection object manages communication with the database and allows executing statements and queries.

Uploaded by

javathagnam
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views9 pages

What Is JDBC?

JDBC is a set of Java APIs that allow Java programs to connect to databases. It includes interfaces and classes for connecting to a database via a JDBC driver, executing SQL statements, and processing the results. Common JDBC drivers support connecting to databases like Oracle, MySQL, SQL Server, and more. The Connection object manages communication with the database and allows executing statements and queries.

Uploaded by

javathagnam
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

What is JDBC?

o JDBC is a set of programming APIs that allows easy connection to a wide range of databases (especially relational databases) through Java programs.

o The following are core JDBC classes, interfaces, and exceptions in the java.sql package: 1. Driver Manager 2. Connection 3. Statement 4. Prepared Statement 5. Callable Statement 6. Result Set 7. SQL Exception A JDBC driver allows a Java application/client to communicate with a SQL database. A JDBC driver is a Java class that implements the JDBC's java.sql.Driver interface. A JDBC driver converts program (and typically SQL) requests for a particular database.

A List of JDBC Drivers


IBM DB2 jdbc:db2://<HOST>:<PORT>/<DB> COM.ibm.db2.jdbc.app.DB2Driver JDBC-ODBC Bridge jdbc:odbc:<DB> sun.jdbc.odbc.JdbcOdbcDriver Microsoft SQL Server jdbc:weblogic:mssqlserver4:<DB>@<HOST>:<PORT> weblogic.jdbc.mssqlserver4.Driver Oracle Thin jdbc:oracle:thin:@<HOST>:<PORT>:<SID>

oracle.jdbc.driver.OracleDriver PointBase Embedded Server jdbc:pointbase://embedded[:<PORT>]/<DB> com.pointbase.jdbc.jdbcUniversalDriver Cloudscape jdbc:cloudscape:<DB> COM.cloudscape.core.JDBCDriver Cloudscape RMI jdbc:rmi://<HOST>:<PORT>/jdbc:cloudscape:<DB> RmiJdbc.RJDriver Firebird (JCA/JDBC Driver) jdbc:firebirdsql:[//<HOST>[:<PORT>]/]<DB> org.firebirdsql.jdbc.FBDriver IDS Server jdbc:ids://<HOST>:<PORT>/conn?dsn='<ODBC_DSN_NAME>' ids.sql.IDSDriver Informix Dynamic Server jdbc:informix-sqli://<HOST>:<PORT>/<DB>:INFORMIXSERVER=<SERVER_NAME> com.informix.jdbc.IfxDriver InstantDB (v3.13 and earlier) jdbc:idb:<DB> jdbc.idbDriver InstantDB (v3.14 and later) jdbc:idb:<DB> org.enhydra.instantdb.jdbc.idbDriver Interbase (InterClient Driver) jdbc:interbase://<HOST>/<DB> interbase.interclient.Driver Hypersonic SQL (v1.2 and earlier) jdbc:HypersonicSQL:<DB> hSql.hDriver Hypersonic SQL (v1.3 and later) jdbc:HypersonicSQL:<DB> org.hsql.jdbcDriver Microsoft SQL Server (JTurbo Driver) jdbc:JTurbo://<HOST>:<PORT>/<DB> com.ashna.jturbo.driver.Driver

Microsoft SQL Server (Sprinta Driver) jdbc:inetdae:<HOST>:<PORT>?database=<DB> com.inet.tds.TdsDriver Microsoft SQL Server 2000 (Microsoft Driver) jdbc:microsoft:sqlserver://<HOST>:<PORT>[;DatabaseName=<DB>] com.microsoft.jdbc.sqlserver.SQLServerDriver MySQL (MM.MySQL Driver) jdbc:mysql://<HOST>:<PORT>/<DB> org.gjt.mm.mysql.Driver Oracle OCI 8i jdbc:oracle:oci8:@<SID> oracle.jdbc.driver.OracleDriver Oracle OCI 9i jdbc:oracle:oci:@<SID> oracle.jdbc.driver.OracleDriver PostgreSQL (v6.5 and earlier) jdbc:postgresql://<HOST>:<PORT>/<DB> postgresql.Driver PostgreSQL (v7.0 and later) jdbc:postgresql://<HOST>:<PORT>/<DB> org.postgresql.Driver Sybase (jConnect 4.2 and earlier) jdbc:sybase:Tds:<HOST>:<PORT> com.sybase.jdbc.SybDriver Sybase (jConnect 5.2) jdbc:sybase:Tds:<HOST>:<PORT> com.sybase.jdbc2.jdbc.SybDriver

Connection Object
The Connection object has the following capabilities: 1. Creates SQL statements . 2. Executes SQL queries, inserts, updates, and deletes . 3. Handles commits and rollbacks . 4. Provides metadata regarding the database connection.

By default, a Connection object is in autocommit mode, which means it automatically commits Changes after executing each statement

Vendor Sample

Driver Name

URL jdb jdb jdb jdb

Oracle 8i oracle.jdbc.driver.OracleDriver c:oracle:thin:@localhost:1521:yourDatabase Oracle 9i oracle.jdbc.driver.OracleDriver c:oracle:thin:@localhost:1521:yourDatabase MySQL org.gjt.mm.mysql.Driver c:mysql://localhost/yourDatabase Microsoft Access c:odbc:scorpian sun.jdbc.odbc.JdbcOdbcDriver

Sybase(jConnect 5.2) com.sybase.jdbc2.jdbc.SybDriver c:sybase:Tds:scorpian:2638 MS SQL Server 2000 com.microsoft.jdbc. sqlserver.SQLServerDriver c:microsoft:sqlserver://localhost:1433 MS SQL Server 2000 weblogic.jdbc.mssqlserver4.Driver c:weblogic:mssqlserver4:database@ localhost:port IBM DB2 COM.ibm.db2.jdbc.net.DB2Connection c:db2://localhost:6789/yourDatabase

jdb

jdb jdb jdb

TYPES

OF

DRIVER

JDBC-ODBC bridge plus ODBC driver, also called Type 1. Native-API, partly Java driver, also called Type 2. JDBC-Net, pure Java driver, also called Type 3. Native-protocol, pure Java driver, also called Type 4.

HOW TO

CREATE TABLE

PACKAGE

USING SQL

import java.sql.*; public class CreateTable{ public static void main(String[] args) { System.out.println("Table Creation Example!"); Connection con = null; String url = "jdbc:odbc:"; String dbName = "Employee"; String driverName = "sun.jdbc.odbc.JdbcOdbcDriver"; String userName = "sa"; String password = "sa"; Try { Class.forName(driverName).newInstance(); con = DriverManager.getConnection(url+dbName, userName, password); try{ Statement st = con.createStatement(); String table = "CREATE TABLE Employee11(Emp_code integer, Emp_name varchar(10))";

st.executeUpdate(table); System.out.println("Table creation process successfully!"); } catch(SQLException s){ System.out.println("Table all ready exists!"); } con.close(); } catch (Exception e){ e.printStackTrace(); } } }

try{ Class.forName(driver); con = DriverManager.getConnection(url+db,"root","root"); try{ Statement st = con.createStatement(); int val = st.executeUpdate("INSERT employee VALUES("+13+","+"'Aman'"+ ")"); System.out.println("1 row affected"); } catch (SQLException s){ System.out.println("SQL statement is not executed!"); } } catch (Exception e){ e.printStackTrace(); } } }

TYPE -1

Eg : JDBC-ODBC Bridge

TYPE -2

Eg :

SQLSERVER , ORACLE

TYPE-3

TYPE4

You might also like