web b-2 ch-4
web b-2 ch-4
Architecture of JDBC
Sumaya academy
G61 near walia nursing home opposite metro pillar 40
Laxminagar delhi-32
8826767298,8826764330
Sumaya academy
G61 near walia nursing home opposite metro pillar 40
Laxminagar delhi-32
8826767298,8826764330
Architecture of JDBC
Description:
1. Application: It is a java applet or a servlet that communicates with a data
source.
2. The JDBC API: The JDBC API allows Java programs to execute SQL
statements and retrieve results. Some of the important classes and
interfaces defined in JDBC API are as follows:
3. DriverManager: It plays an important role in the JDBC architecture. It
uses some database-specific drivers to effectively connect enterprise
applications to databases.
4. JDBC drivers: To communicate with a data source through JDBC, you
need a JDBC driver that intelligently communicates with the respective
data source.
JDBC Drivers
JDBC drivers are client-side adapters (installed on the client machine, not on
the server) that convert requests from Java programs to a protocol that the
DBMS can understand. There are 4 types of JDBC drivers:
1. Type-1 driver or JDBC-ODBC bridge driver
2. Type-2 driver or Native-API driver
3. Type-3 driver or Network Protocol driver
4. Type-4 driver or Thin driver
package com.vinayak.jdbc;
import java.sql.*;
String driverClassName
= "sun.jdbc.odbc.JdbcOdbcDriver";
String query
Class.forName(driverClassName);
// Obtain a connection
// Obtain a statement
Statement st = con.createStatement();
Sumaya academy
G61 near walia nursing home opposite metro pillar 40
Laxminagar delhi-32
8826767298,8826764330
System.out.println(
+ count);
con.close();
} // class
The instance of ServletContext is created only once by the web container when application or
project is deployed on the server.
This object can be used to get initialization parameter from configuaration file (web.xml). It
can also be used to get, set or remove attribute from the application scope.
1. <form action="welcome">
2. <input type="text" name="uname">
3. <input type="submit" value="go"><br/>
4. </form>
web.xml file
1. <web-app>
2.
3. <servlet>
4. <servlet-name>sonoojaiswal</servlet-name>
5. <jsp-file>/welcome.jsp</jsp-file>
6. </servlet>
7.
8. <servlet-mapping>
9. <servlet-name>sonoojaiswal</servlet-name>
10. <url-pattern>/welcome</url-pattern>
11. </servlet-mapping>
12.
13. <context-param>
14. <param-name>dname</param-name>
15. <param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>
16. </context-param>
17.
18. </web-app>
welcome.jsp
1. <%
2.
3. out.print("Welcome "+request.getParameter("uname"));
4.
5. String driver=application.getInitParameter("dname");
6. out.print("driver name is="+driver);
7.
8. %>
Sumaya academy
G61 near walia nursing home opposite metro pillar 40
Laxminagar delhi-32
8826767298,8826764330
Output
Advantage of JSTL
1. Fast Development JSTL provides many tags that simplify the JSP.
2. Code Reusability We can use the JSTL tags on various pages.
3. No need to use scriptlet tag It avoids the use of scriptlet tag.
Sumaya academy
G61 near walia nursing home opposite metro pillar 40
Laxminagar delhi-32
8826767298,8826764330
JSTL Tags
There JSTL mainly provides five types of tags:
Tag Description
Name
Core tags The JSTL core tag provide variable support, URL management, flow control,
etc. The URL for the core tag is http://java.sun.com/jsp/jstl/core. The
prefix of core tag is c.
Function The functions tags provide support for string manipulation and string
tags length. The URL for the functions tags
is http://java.sun.com/jsp/jstl/functions and prefix is fn.
Formatting The Formatting tags provide support for message formatting, number and
tags date formatting, etc. The URL for the Formatting tags
is http://java.sun.com/jsp/jstl/fmt and prefix is fmt.
XML tags The XML tags provide flow control, transformation, etc. The URL for the
XML tags is http://java.sun.com/jsp/jstl/xml and prefix is x.
SQL tags The JSTL SQL tags provide SQL support. The URL for the SQL tags
is http://java.sun.com/jsp/jstl/sql and prefix is sql.
Sumaya academy
G61 near walia nursing home opposite metro pillar 40
Laxminagar delhi-32
8826767298,8826764330
Sumaya academy
G61 near walia nursing home opposite metro pillar 40
Laxminagar delhi-32
8826767298,8826764330