Client Server Computing - Full Notes (Short & Simple)
Unit I: Java Database Connectivity (JDBC)
- JDBC API: Interface between Java and Database.
- DriverManager: Loads appropriate driver.
- Connection: Connects to the database.
- Statement: Executes SQL queries (static).
- PreparedStatement: Executes parameterized queries, safer from SQL injection.
- CallableStatement: Executes stored procedures.
- ResultSet: Holds query results.
- Types of ResultSet: TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, etc.
- Operations: SELECT, INSERT, UPDATE, DELETE.
- Display results using ResultSet.
- Stored Procedures: Precompiled SQL on server.
Example:
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/db", "root", "");
PreparedStatement ps = con.prepareStatement("SELECT * FROM users");
ResultSet rs = ps.executeQuery();
while(rs.next()) {
System.out.println(rs.getString("username"));
Unit II: Servlets in Java
- Servlet Lifecycle: init(), service(), destroy()
- API Basics: HttpServlet, ServletConfig, ServletContext
- Interfaces: Servlet, ServletRequest, ServletResponse
- Writing & running servlets, configuring web.xml
- Handling Cookies and Sessions
- Request forwarding & Servlet chaining
- JDBC with Servlets for database interaction
Example:
public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
PrintWriter out = res.getWriter();
out.println("Hello Servlet");
Unit III: Introduction to JSP
- JSP Concepts: Combines HTML and Java
- JSP Lifecycle: Translation -> Compilation -> Execution
- Scripting Elements: <% code %>, <%= output %>, <%! declaration %>
- Directives: <%@ page %>, <%@ include %>, <%@ taglib %>
- Implicit Objects: request, response, session, application, out, etc.
- JavaBeans: Encapsulated reusable components with properties and methods
- Bean Usage: Create, set, get values in JSP
Example:
<jsp:useBean id="u" class="com.User" scope="session" />
<jsp:setProperty name="u" property="username" value="John" />
<jsp:getProperty name="u" property="username" />
- JSP Actions: <jsp:useBean>, <jsp:setProperty>, <jsp:getProperty>
- JSTL: Java Standard Tag Library (Core, SQL, XML, Functions)
Example JSTL:
<c:if test="${user != null}">
Welcome ${user.name}
</c:if>