What is JDBC?
Java Database Connectivity is a technique of connect java front end to back end database and allowing the retrieval and manipulation of data in the database using java.
---------------------------------------------------------------------------------------------
How do you connect to the Database?
The process of using JDBC to connect to the database is as follows:
1. Register the driver:
Class.forName(”driverName”);
for example, sun.jdbc.odbc.JdbcOdbcDriver
2. Making the connection using DriverManager Class’s
getConnection method :
Connection con = DriverManager.getConnection(”url,”myLogin”,myPassword”);
For example url may be jdbc:odbc:dsn_name.
3. Creating the JDBC Statement and Retreiving:
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
4. Handling SQL Exception
---------------------------------------------------------------------------------------------
What are the drivers and when it will use?
JDBC-ODBC Bridge Driver for Java and Database (Java Application)
JDBC-Net pure java driver for Applet and Database(Applet application)
Native-API partly Java driver for Native class and Database (for network application)
Native Protocol pure java driver for vendor specfic application
(EJB application)
No comments:
Post a Comment