Vision Academy – Training Institute in Pune Hadapsar is a pioneer in training Institutes providing various professional training courses for multiple technologies. Proficient professionals and experts constitute an institute. We are working on technological domains as a centre for education to give a comprehensive and most exceptional learning experience in various technologies. TIP is the Leading Professional Training Institute for SEO, Digital Marketing Courses in Pune. We also offer other IT Training’s like AngularJS, MVC, Python, Salesforce, Data Science, AI, Blockchain Hadoop, RPA (Blue Prism, Automation Anywhere, and UI Path) Informatics, Selenium. Our Specialty is that we provide Hands-on Training for all Courses, and All Trainers at our Institute are from MNC’s.
JDBC (Java Database Connectivity) provides APIs for Java programs to connect to databases. There are four types of JDBC drivers: Type 1 uses JDBC-ODBC bridge, Type 2 uses a native API, Type 3 is pure Java using a network protocol, and Type 4 is also pure Java using a native database protocol.
To connect to a database using JDBC, a program loads the appropriate JDBC driver, gets a connection, creates statements to execute SQL queries and updates, processes the result set, and closes resources. Prepared statements can be used for repetitive queries to improve performance over regular statements. Overall, JDBC allows Java applications to connect to databases in a standardized way
The document provides an overview of J2EE (Java 2 Enterprise Edition) and its core technologies including JDBC, Servlets, JSP, EJB, and RMI. It then discusses JDBC in more detail, explaining the JDBC architecture, drivers, and basic steps to access a database using JDBC including loading drivers, connecting, executing statements, processing results, and closing connections. It also covers PreparedStatement and CallableStatement objects.
This document provides an overview of JDBC (Java Database Connectivity) including ODBC, the JDBC API, JDBC architecture and drivers, and the basic steps for using JDBC to connect to and query a database.
The document discusses Java Database Connectivity (JDBC) and how to connect a Java application to a database. It describes that JDBC is a Java API that uses JDBC drivers to connect to databases. There are four types of JDBC drivers: JDBC-ODBC bridge driver, native API driver, network protocol driver, and thin driver. It provides code examples for how to register the driver, create a connection, execute statements, and close the connection in five steps using the Oracle database as an example.
The document discusses JDBC (Java Database Connectivity), which provides Java applications with methods to access databases. It covers JDBC architecture and driver types, including Type 1 (JDBC-ODBC bridge), Type 2 (native API), Type 3 (network protocol), and Type 4 (pure Java) drivers. The key classes and interfaces of the JDBC API are also summarized, along with the typical steps to connect to a database using JDBC: loading a driver, connecting, executing statements, and handling exceptions.
This document provides an overview of Java Database Connectivity (JDBC) in 3 sentences or less:
JDBC allows Java programs to connect to and interact with various database systems and provides a standard API for querying and manipulating data in relational databases. The key components of JDBC include the DriverManager, Connection, Statement, and ResultSet objects, and connecting to a database typically involves 4 steps - loading a driver, opening a connection, executing SQL statements via a Statement object, and processing result sets. JDBC offers database independence and ease of administration along with the ability to access any database from Java applications.
The document discusses Java Database Connectivity (JDBC) API which defines how Java programs can communicate with databases. It describes key JDBC concepts like drivers, packages, and products. It also covers JDBC design considerations like different types of drivers and client-server models. Basic steps to use JDBC include loading drivers, establishing connections, executing statements, and closing connections.
JDBC (Java Database Connectivity) provides APIs for Java programs to connect to databases. There are four types of JDBC drivers: Type 1 uses JDBC-ODBC bridge, Type 2 uses a native API, Type 3 is pure Java using a network protocol, and Type 4 is also pure Java using a native database protocol.
To connect to a database using JDBC, a program loads the appropriate JDBC driver, gets a connection, creates statements to execute SQL queries and updates, processes the result set, and closes resources. Prepared statements can be used for repetitive queries to improve performance over regular statements. Overall, JDBC allows Java applications to connect to databases in a standardized way
The document provides an overview of J2EE (Java 2 Enterprise Edition) and its core technologies including JDBC, Servlets, JSP, EJB, and RMI. It then discusses JDBC in more detail, explaining the JDBC architecture, drivers, and basic steps to access a database using JDBC including loading drivers, connecting, executing statements, processing results, and closing connections. It also covers PreparedStatement and CallableStatement objects.
This document provides an overview of JDBC (Java Database Connectivity) including ODBC, the JDBC API, JDBC architecture and drivers, and the basic steps for using JDBC to connect to and query a database.
The document discusses Java Database Connectivity (JDBC) and how to connect a Java application to a database. It describes that JDBC is a Java API that uses JDBC drivers to connect to databases. There are four types of JDBC drivers: JDBC-ODBC bridge driver, native API driver, network protocol driver, and thin driver. It provides code examples for how to register the driver, create a connection, execute statements, and close the connection in five steps using the Oracle database as an example.
The document discusses JDBC (Java Database Connectivity), which provides Java applications with methods to access databases. It covers JDBC architecture and driver types, including Type 1 (JDBC-ODBC bridge), Type 2 (native API), Type 3 (network protocol), and Type 4 (pure Java) drivers. The key classes and interfaces of the JDBC API are also summarized, along with the typical steps to connect to a database using JDBC: loading a driver, connecting, executing statements, and handling exceptions.
This document provides an overview of Java Database Connectivity (JDBC) in 3 sentences or less:
JDBC allows Java programs to connect to and interact with various database systems and provides a standard API for querying and manipulating data in relational databases. The key components of JDBC include the DriverManager, Connection, Statement, and ResultSet objects, and connecting to a database typically involves 4 steps - loading a driver, opening a connection, executing SQL statements via a Statement object, and processing result sets. JDBC offers database independence and ease of administration along with the ability to access any database from Java applications.
The document discusses Java Database Connectivity (JDBC) API which defines how Java programs can communicate with databases. It describes key JDBC concepts like drivers, packages, and products. It also covers JDBC design considerations like different types of drivers and client-server models. Basic steps to use JDBC include loading drivers, establishing connections, executing statements, and closing connections.
This document discusses JDBC (Java Database Connectivity), which provides a standard interface for connecting Java applications to various databases. It describes JDBC drivers that translate JDBC calls to database-specific calls, including four major types. The seven steps for connecting a Java application to a database using JDBC are outlined, including importing necessary packages, loading drivers, establishing a connection, creating statements, executing queries, retrieving results, and closing connections. Key classes like Connection, Statement, and ResultSet are also introduced.
JDBC provides an API for connecting to and interacting with databases in Java. It defines interfaces and classes for establishing a connection with a database, issuing SQL statements, processing result sets, and handling exceptions. The key classes in JDBC include DriverManager, Connection, Statement, PreparedStatement, CallableStatement, and ResultSet. There are four types of JDBC drivers: Type 1 (JDBC-ODBC bridge), Type 2 (native API), Type 3 (network protocol), and Type 4 (native protocol). Connecting to a database in JDBC involves loading the driver, getting a connection, creating statements, executing queries, processing results, and closing the connection.
Project : Airline Reservation System
Objective : To design an Airline Reservation System application which enables the customers to search, book and cancel flights.
Description :
- Implemented using NetBeans IDE and MySQL Server
- Concepts of JAVA, DBMS and JDBC are used
The document discusses Java Database Connectivity (JDBC), which provides a standard interface for connecting to relational databases from Java applications. It describes the JDBC model and programming steps, which include loading a JDBC driver, connecting to a database, executing SQL statements via a Statement object, processing query results stored in a ResultSet, and closing connections. It also covers JDBC driver types, the roles of core classes like Connection and Statement, and transaction handling with JDBC.
Synopsis on online shopping by sudeep singhSudeep Singh
This document provides an overview of an online shopping project developed using Java. It discusses the aims of improving customer and vendor services. It maintains customer payment and product details. The key features are high accuracy, flexibility and easy availability. It uses database tables to represent entities and relationships. The project allows customers to shop online and buy items which are then shipped to the submitted address. It has modules for customers and stores.
This document discusses Java Database Connectivity (JDBC) and its components. It begins with an introduction to JDBC, explaining that JDBC is a Java API that allows Java programs to execute SQL statements and interact with multiple database sources. It then discusses the four types of JDBC drivers - JDBC-ODBC bridge drivers, native-API partly Java drivers, network protocol all-Java drivers, and native protocol all-Java drivers - and their characteristics. The document proceeds to explain the standard seven steps to querying databases using JDBC: loading the driver, defining the connection URL, establishing the connection, creating a statement object, executing a query or update, processing results, and closing the connection.
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2Vladimir Bacvanski, PhD
Vladimir Bacvanski and Dan Galvin
Looking for a more flexible and efficient way for Java programs to access the database? Join us as we explore how you can
bridge the gap between Java and relational databases. Enhance your Java environment with access layer generation, data
access best practices, traceability between Java packages and SQL statements, improved impact analysis and more. And most importantly, see how new technology can improve not only new development, but existing applications as well. Be prepared to
see designs and code samples!
Introduction to JDBC and database access in web applicationsFulvio Corno
Introduction to the JDBC standard and best practices for database access from Web Applications.
Materiale realizzato per il corso di Sistemi Informativi Aziendali del Politecnico di Torino - http://bit.ly/sistinfo
This document discusses Java Database Connectivity (JDBC) which provides a standard interface for connecting Java applications to various databases. It describes the JDBC API and architecture, including the four types of JDBC drivers. The key points are:
1) JDBC provides a standard way for Java programs to access any SQL database. It uses JDBC drivers implemented by database vendors to translate JDBC calls into database-specific protocols.
2) The JDBC API has two layers - an application layer used by developers, and a driver layer implemented by vendors. There are four main interfaces (Driver, Connection, Statement, ResultSet) and the DriverManager class.
3) There are
This document discusses Java Database Connectivity (JDBC) which provides a standard interface for connecting Java applications to various databases. It describes the JDBC API and architecture, including the four types of JDBC drivers. The key points are:
1) JDBC provides a standard way for Java programs to access any SQL database. It uses JDBC drivers implemented by database vendors to translate JDBC calls into database-specific protocols.
2) The JDBC API has two layers - an application layer used by developers, and a driver layer implemented by vendors. There are four main interfaces (Driver, Connection, Statement, ResultSet) and the DriverManager class.
3) There are
Dịch vụ : Thiết kế website (http://www.web360.com.vn/) - Dịch vụ thiết kế web khách sạn (http://web360.com.vn/Thiet-ke-Web-khach-san.html)
Web360 công ty thiết kế web với nhiều năm kinh nghiệm , chúng tôi cung cấp các giải pháp dành cho những khách hàng có nhu cầu xây dựng website để đẩy mạnh công việc kinh doanh, mở rộng các kênh bán hàng, tăng cường khả năng giao tiếp với khách hàng hoặc muốn khẳng định đẳng cấp hoặc thương hiệu của công ty.
Thiết kế web giá rẻ nhất đà nẵng(http://web360.com.vn/Thiet-ke-web-gia-re-da-nang.html)
DỊCH VỤ THIẾT KẾ WEB CHUYÊN NGHIỆP CỦA CHÚNG TÔI NHƯ SAU :
1. Giao diện website được thiết kế đẹp mắt, chuyên nghiệp.
2. Website được nghiên cứu kỹ các đối tượng khách hàng, phân tích nhu cầu, thói quen và hành vi của họ khi duyệt web để xây dựng các chức năng và nội dung phù hợp nhằm biến họ trở thành khách hàng thực sự của bạn.
3. Nghiên cứu rất kỹ các đối thủ cạnh tranh của bạn trên mạngi internet và sẽ tư vấn cho bạn cách để bạn vượt qua họ.
4. Các chuyên gia của chúng tôi cũng sẽ tư vấn cho bạn cách viết nội dung và sử dụng những từ khóa có giá trị nhằm thu hút và giữ chân khách hàng, đồng thời tạo thiện cảm cho các công cụ tìm kiếm.
5. Tối ưu hóa công cụ tìm kiếm chuẩn SEO google
Liên hệ với chúng tôi để được tư vấn thiết kế web tại Đà Nẵng tận tình nhất !
Thiet ke web da nang - Cong ty thiet ke web tai da nang (http://web360.com.vn/Thiet-ke-web-Da-Nang.html)
Liên hệ : 090.52.52.360 - 0905.595.360(Mr Hoàng)
Email : info@web360.com.vn (info@web360.com.vn)
Website : www.web360.com.vn (http://web360.com.vn/)
Địa chỉ : 44 Ngô Chi Lan - Q.Hải Châu - TP.Đà Nẵng
Chúng tôi luôn nỗ lực đem lại cho khách hàng những sản phẩm và dịch vụ tốt nhất !
dịch vụ,thiết kế,thiết kế web,chuyên nghiệp,dịch vụ thiết kế,dịch vụ thiết kế web đà nẵng
This document provides an overview of using JDBC (Java Database Connectivity) to connect to and query databases. It discusses the basic 7 steps to using JDBC including loading drivers, establishing a connection, creating statements, executing queries, processing result sets, and closing connections. It also covers more advanced topics like using prepared statements, callable statements, metadata, transactions, and defining data sources using JNDI. Examples are provided using the Microsoft Access Northwind sample database accessed via JDBC-ODBC bridge.
Lecture 13 from the IAG0040 Java course in TTÜ.
See the accompanying source code written during the lectures: https://github.com/angryziber/java-course
The document discusses Java annotations and JDBC. It begins by defining annotations and describing several built-in Java annotations like @Override, @Deprecated, and @SuppressWarnings. It then covers user-defined or custom annotations. The document also provides an overview of JDBC architecture and drivers, and describes the essential steps to connect to a database and execute queries using JDBC, including using prepared statements and result sets. It concludes with sections on batch updates and an interactive SQL tool.
The document provides an overview of Core JDBC basics, including:
- JDBC defines interfaces and classes for connecting to databases and executing SQL statements from Java code. It standardizes connecting to databases, executing queries, navigating results, and updates.
- There are four main types of JDBC drivers: JDBC-ODBC bridge, native API, network protocol, and thin drivers. Thin drivers provide the best performance by directly converting JDBC calls to database protocols.
- The basic steps to connect using JDBC are: register the driver, get a connection, create statements to execute queries and updates, handle result sets, and close the connection. Transactions allow grouping statements
This document discusses Java Database Connectivity (JDBC) which provides Java applications with an API for accessing databases. It describes the four types of JDBC drivers: Type 1 uses JDBC-ODBC bridge, Type 2 uses native database APIs, Type 3 communicates through a middle-tier server, and Type 4 communicates directly via sockets. The document also outlines the basic steps to use JDBC for database connectivity including loading a driver, establishing a connection, creating statements, executing SQL, and processing result sets.
Mumbai Academics is Mumbai’s first dedicated Professional Training Center for Training with Spoke and hub model with Multiple verticles . The strong foundation of Mumbai Academics is laid by highly skilled and trained Professionals, carrying mission to provide industry level input to the freshers and highly skilled and trained Software Professionals/other professional to IT companies.
The JDBC-ODBC bridge driver converts JDBC calls to ODBC calls so that Java programs can connect to databases for which native JDBC drivers do not exist. It allows connection to many databases but requires ODBC drivers and has performance overhead due to translation. Native JDBC drivers are preferred when available.
The two-tier database architecture has the Java application directly connecting to the database using a JDBC driver. The three-tier architecture separates the presentation, application and data tiers with the application server in the middle handling requests and communicating with the database server.
Dandelion Hashtable: beyond billion requests per second on a commodity serverAntonios Katsarakis
This slide deck presents DLHT, a concurrent in-memory hashtable. Despite efforts to optimize hashtables, that go as far as sacrificing core functionality, state-of-the-art designs still incur multiple memory accesses per request and block request processing in three cases. First, most hashtables block while waiting for data to be retrieved from memory. Second, open-addressing designs, which represent the current state-of-the-art, either cannot free index slots on deletes or must block all requests to do so. Third, index resizes block every request until all objects are copied to the new index. Defying folklore wisdom, DLHT forgoes open-addressing and adopts a fully-featured and memory-aware closed-addressing design based on bounded cache-line-chaining. This design offers lock-free index operations and deletes that free slots instantly, (2) completes most requests with a single memory access, (3) utilizes software prefetching to hide memory latencies, and (4) employs a novel non-blocking and parallel resizing. In a commodity server and a memory-resident workload, DLHT surpasses 1.6B requests per second and provides 3.5x (12x) the throughput of the state-of-the-art closed-addressing (open-addressing) resizable hashtable on Gets (Deletes).
Monitoring and Managing Anomaly Detection on OpenShift.pdfTosin Akinosho
Monitoring and Managing Anomaly Detection on OpenShift
Overview
Dive into the world of anomaly detection on edge devices with our comprehensive hands-on tutorial. This SlideShare presentation will guide you through the entire process, from data collection and model training to edge deployment and real-time monitoring. Perfect for those looking to implement robust anomaly detection systems on resource-constrained IoT/edge devices.
Key Topics Covered
1. Introduction to Anomaly Detection
- Understand the fundamentals of anomaly detection and its importance in identifying unusual behavior or failures in systems.
2. Understanding Edge (IoT)
- Learn about edge computing and IoT, and how they enable real-time data processing and decision-making at the source.
3. What is ArgoCD?
- Discover ArgoCD, a declarative, GitOps continuous delivery tool for Kubernetes, and its role in deploying applications on edge devices.
4. Deployment Using ArgoCD for Edge Devices
- Step-by-step guide on deploying anomaly detection models on edge devices using ArgoCD.
5. Introduction to Apache Kafka and S3
- Explore Apache Kafka for real-time data streaming and Amazon S3 for scalable storage solutions.
6. Viewing Kafka Messages in the Data Lake
- Learn how to view and analyze Kafka messages stored in a data lake for better insights.
7. What is Prometheus?
- Get to know Prometheus, an open-source monitoring and alerting toolkit, and its application in monitoring edge devices.
8. Monitoring Application Metrics with Prometheus
- Detailed instructions on setting up Prometheus to monitor the performance and health of your anomaly detection system.
9. What is Camel K?
- Introduction to Camel K, a lightweight integration framework built on Apache Camel, designed for Kubernetes.
10. Configuring Camel K Integrations for Data Pipelines
- Learn how to configure Camel K for seamless data pipeline integrations in your anomaly detection workflow.
11. What is a Jupyter Notebook?
- Overview of Jupyter Notebooks, an open-source web application for creating and sharing documents with live code, equations, visualizations, and narrative text.
12. Jupyter Notebooks with Code Examples
- Hands-on examples and code snippets in Jupyter Notebooks to help you implement and test anomaly detection models.
More Related Content
Similar to Vision_Academy_Ajava_final(sachin_sir9823037693)_22.pdf
This document discusses JDBC (Java Database Connectivity), which provides a standard interface for connecting Java applications to various databases. It describes JDBC drivers that translate JDBC calls to database-specific calls, including four major types. The seven steps for connecting a Java application to a database using JDBC are outlined, including importing necessary packages, loading drivers, establishing a connection, creating statements, executing queries, retrieving results, and closing connections. Key classes like Connection, Statement, and ResultSet are also introduced.
JDBC provides an API for connecting to and interacting with databases in Java. It defines interfaces and classes for establishing a connection with a database, issuing SQL statements, processing result sets, and handling exceptions. The key classes in JDBC include DriverManager, Connection, Statement, PreparedStatement, CallableStatement, and ResultSet. There are four types of JDBC drivers: Type 1 (JDBC-ODBC bridge), Type 2 (native API), Type 3 (network protocol), and Type 4 (native protocol). Connecting to a database in JDBC involves loading the driver, getting a connection, creating statements, executing queries, processing results, and closing the connection.
Project : Airline Reservation System
Objective : To design an Airline Reservation System application which enables the customers to search, book and cancel flights.
Description :
- Implemented using NetBeans IDE and MySQL Server
- Concepts of JAVA, DBMS and JDBC are used
The document discusses Java Database Connectivity (JDBC), which provides a standard interface for connecting to relational databases from Java applications. It describes the JDBC model and programming steps, which include loading a JDBC driver, connecting to a database, executing SQL statements via a Statement object, processing query results stored in a ResultSet, and closing connections. It also covers JDBC driver types, the roles of core classes like Connection and Statement, and transaction handling with JDBC.
Synopsis on online shopping by sudeep singhSudeep Singh
This document provides an overview of an online shopping project developed using Java. It discusses the aims of improving customer and vendor services. It maintains customer payment and product details. The key features are high accuracy, flexibility and easy availability. It uses database tables to represent entities and relationships. The project allows customers to shop online and buy items which are then shipped to the submitted address. It has modules for customers and stores.
This document discusses Java Database Connectivity (JDBC) and its components. It begins with an introduction to JDBC, explaining that JDBC is a Java API that allows Java programs to execute SQL statements and interact with multiple database sources. It then discusses the four types of JDBC drivers - JDBC-ODBC bridge drivers, native-API partly Java drivers, network protocol all-Java drivers, and native protocol all-Java drivers - and their characteristics. The document proceeds to explain the standard seven steps to querying databases using JDBC: loading the driver, defining the connection URL, establishing the connection, creating a statement object, executing a query or update, processing results, and closing the connection.
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2Vladimir Bacvanski, PhD
Vladimir Bacvanski and Dan Galvin
Looking for a more flexible and efficient way for Java programs to access the database? Join us as we explore how you can
bridge the gap between Java and relational databases. Enhance your Java environment with access layer generation, data
access best practices, traceability between Java packages and SQL statements, improved impact analysis and more. And most importantly, see how new technology can improve not only new development, but existing applications as well. Be prepared to
see designs and code samples!
Introduction to JDBC and database access in web applicationsFulvio Corno
Introduction to the JDBC standard and best practices for database access from Web Applications.
Materiale realizzato per il corso di Sistemi Informativi Aziendali del Politecnico di Torino - http://bit.ly/sistinfo
This document discusses Java Database Connectivity (JDBC) which provides a standard interface for connecting Java applications to various databases. It describes the JDBC API and architecture, including the four types of JDBC drivers. The key points are:
1) JDBC provides a standard way for Java programs to access any SQL database. It uses JDBC drivers implemented by database vendors to translate JDBC calls into database-specific protocols.
2) The JDBC API has two layers - an application layer used by developers, and a driver layer implemented by vendors. There are four main interfaces (Driver, Connection, Statement, ResultSet) and the DriverManager class.
3) There are
This document discusses Java Database Connectivity (JDBC) which provides a standard interface for connecting Java applications to various databases. It describes the JDBC API and architecture, including the four types of JDBC drivers. The key points are:
1) JDBC provides a standard way for Java programs to access any SQL database. It uses JDBC drivers implemented by database vendors to translate JDBC calls into database-specific protocols.
2) The JDBC API has two layers - an application layer used by developers, and a driver layer implemented by vendors. There are four main interfaces (Driver, Connection, Statement, ResultSet) and the DriverManager class.
3) There are
Dịch vụ : Thiết kế website (http://www.web360.com.vn/) - Dịch vụ thiết kế web khách sạn (http://web360.com.vn/Thiet-ke-Web-khach-san.html)
Web360 công ty thiết kế web với nhiều năm kinh nghiệm , chúng tôi cung cấp các giải pháp dành cho những khách hàng có nhu cầu xây dựng website để đẩy mạnh công việc kinh doanh, mở rộng các kênh bán hàng, tăng cường khả năng giao tiếp với khách hàng hoặc muốn khẳng định đẳng cấp hoặc thương hiệu của công ty.
Thiết kế web giá rẻ nhất đà nẵng(http://web360.com.vn/Thiet-ke-web-gia-re-da-nang.html)
DỊCH VỤ THIẾT KẾ WEB CHUYÊN NGHIỆP CỦA CHÚNG TÔI NHƯ SAU :
1. Giao diện website được thiết kế đẹp mắt, chuyên nghiệp.
2. Website được nghiên cứu kỹ các đối tượng khách hàng, phân tích nhu cầu, thói quen và hành vi của họ khi duyệt web để xây dựng các chức năng và nội dung phù hợp nhằm biến họ trở thành khách hàng thực sự của bạn.
3. Nghiên cứu rất kỹ các đối thủ cạnh tranh của bạn trên mạngi internet và sẽ tư vấn cho bạn cách để bạn vượt qua họ.
4. Các chuyên gia của chúng tôi cũng sẽ tư vấn cho bạn cách viết nội dung và sử dụng những từ khóa có giá trị nhằm thu hút và giữ chân khách hàng, đồng thời tạo thiện cảm cho các công cụ tìm kiếm.
5. Tối ưu hóa công cụ tìm kiếm chuẩn SEO google
Liên hệ với chúng tôi để được tư vấn thiết kế web tại Đà Nẵng tận tình nhất !
Thiet ke web da nang - Cong ty thiet ke web tai da nang (http://web360.com.vn/Thiet-ke-web-Da-Nang.html)
Liên hệ : 090.52.52.360 - 0905.595.360(Mr Hoàng)
Email : info@web360.com.vn (info@web360.com.vn)
Website : www.web360.com.vn (http://web360.com.vn/)
Địa chỉ : 44 Ngô Chi Lan - Q.Hải Châu - TP.Đà Nẵng
Chúng tôi luôn nỗ lực đem lại cho khách hàng những sản phẩm và dịch vụ tốt nhất !
dịch vụ,thiết kế,thiết kế web,chuyên nghiệp,dịch vụ thiết kế,dịch vụ thiết kế web đà nẵng
This document provides an overview of using JDBC (Java Database Connectivity) to connect to and query databases. It discusses the basic 7 steps to using JDBC including loading drivers, establishing a connection, creating statements, executing queries, processing result sets, and closing connections. It also covers more advanced topics like using prepared statements, callable statements, metadata, transactions, and defining data sources using JNDI. Examples are provided using the Microsoft Access Northwind sample database accessed via JDBC-ODBC bridge.
Lecture 13 from the IAG0040 Java course in TTÜ.
See the accompanying source code written during the lectures: https://github.com/angryziber/java-course
The document discusses Java annotations and JDBC. It begins by defining annotations and describing several built-in Java annotations like @Override, @Deprecated, and @SuppressWarnings. It then covers user-defined or custom annotations. The document also provides an overview of JDBC architecture and drivers, and describes the essential steps to connect to a database and execute queries using JDBC, including using prepared statements and result sets. It concludes with sections on batch updates and an interactive SQL tool.
The document provides an overview of Core JDBC basics, including:
- JDBC defines interfaces and classes for connecting to databases and executing SQL statements from Java code. It standardizes connecting to databases, executing queries, navigating results, and updates.
- There are four main types of JDBC drivers: JDBC-ODBC bridge, native API, network protocol, and thin drivers. Thin drivers provide the best performance by directly converting JDBC calls to database protocols.
- The basic steps to connect using JDBC are: register the driver, get a connection, create statements to execute queries and updates, handle result sets, and close the connection. Transactions allow grouping statements
This document discusses Java Database Connectivity (JDBC) which provides Java applications with an API for accessing databases. It describes the four types of JDBC drivers: Type 1 uses JDBC-ODBC bridge, Type 2 uses native database APIs, Type 3 communicates through a middle-tier server, and Type 4 communicates directly via sockets. The document also outlines the basic steps to use JDBC for database connectivity including loading a driver, establishing a connection, creating statements, executing SQL, and processing result sets.
Mumbai Academics is Mumbai’s first dedicated Professional Training Center for Training with Spoke and hub model with Multiple verticles . The strong foundation of Mumbai Academics is laid by highly skilled and trained Professionals, carrying mission to provide industry level input to the freshers and highly skilled and trained Software Professionals/other professional to IT companies.
The JDBC-ODBC bridge driver converts JDBC calls to ODBC calls so that Java programs can connect to databases for which native JDBC drivers do not exist. It allows connection to many databases but requires ODBC drivers and has performance overhead due to translation. Native JDBC drivers are preferred when available.
The two-tier database architecture has the Java application directly connecting to the database using a JDBC driver. The three-tier architecture separates the presentation, application and data tiers with the application server in the middle handling requests and communicating with the database server.
Similar to Vision_Academy_Ajava_final(sachin_sir9823037693)_22.pdf (20)
Dandelion Hashtable: beyond billion requests per second on a commodity serverAntonios Katsarakis
This slide deck presents DLHT, a concurrent in-memory hashtable. Despite efforts to optimize hashtables, that go as far as sacrificing core functionality, state-of-the-art designs still incur multiple memory accesses per request and block request processing in three cases. First, most hashtables block while waiting for data to be retrieved from memory. Second, open-addressing designs, which represent the current state-of-the-art, either cannot free index slots on deletes or must block all requests to do so. Third, index resizes block every request until all objects are copied to the new index. Defying folklore wisdom, DLHT forgoes open-addressing and adopts a fully-featured and memory-aware closed-addressing design based on bounded cache-line-chaining. This design offers lock-free index operations and deletes that free slots instantly, (2) completes most requests with a single memory access, (3) utilizes software prefetching to hide memory latencies, and (4) employs a novel non-blocking and parallel resizing. In a commodity server and a memory-resident workload, DLHT surpasses 1.6B requests per second and provides 3.5x (12x) the throughput of the state-of-the-art closed-addressing (open-addressing) resizable hashtable on Gets (Deletes).
Monitoring and Managing Anomaly Detection on OpenShift.pdfTosin Akinosho
Monitoring and Managing Anomaly Detection on OpenShift
Overview
Dive into the world of anomaly detection on edge devices with our comprehensive hands-on tutorial. This SlideShare presentation will guide you through the entire process, from data collection and model training to edge deployment and real-time monitoring. Perfect for those looking to implement robust anomaly detection systems on resource-constrained IoT/edge devices.
Key Topics Covered
1. Introduction to Anomaly Detection
- Understand the fundamentals of anomaly detection and its importance in identifying unusual behavior or failures in systems.
2. Understanding Edge (IoT)
- Learn about edge computing and IoT, and how they enable real-time data processing and decision-making at the source.
3. What is ArgoCD?
- Discover ArgoCD, a declarative, GitOps continuous delivery tool for Kubernetes, and its role in deploying applications on edge devices.
4. Deployment Using ArgoCD for Edge Devices
- Step-by-step guide on deploying anomaly detection models on edge devices using ArgoCD.
5. Introduction to Apache Kafka and S3
- Explore Apache Kafka for real-time data streaming and Amazon S3 for scalable storage solutions.
6. Viewing Kafka Messages in the Data Lake
- Learn how to view and analyze Kafka messages stored in a data lake for better insights.
7. What is Prometheus?
- Get to know Prometheus, an open-source monitoring and alerting toolkit, and its application in monitoring edge devices.
8. Monitoring Application Metrics with Prometheus
- Detailed instructions on setting up Prometheus to monitor the performance and health of your anomaly detection system.
9. What is Camel K?
- Introduction to Camel K, a lightweight integration framework built on Apache Camel, designed for Kubernetes.
10. Configuring Camel K Integrations for Data Pipelines
- Learn how to configure Camel K for seamless data pipeline integrations in your anomaly detection workflow.
11. What is a Jupyter Notebook?
- Overview of Jupyter Notebooks, an open-source web application for creating and sharing documents with live code, equations, visualizations, and narrative text.
12. Jupyter Notebooks with Code Examples
- Hands-on examples and code snippets in Jupyter Notebooks to help you implement and test anomaly detection models.
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUpanagenda
Webinar Recording: https://www.panagenda.com/webinars/hcl-notes-und-domino-lizenzkostenreduzierung-in-der-welt-von-dlau/
DLAU und die Lizenzen nach dem CCB- und CCX-Modell sind für viele in der HCL-Community seit letztem Jahr ein heißes Thema. Als Notes- oder Domino-Kunde haben Sie vielleicht mit unerwartet hohen Benutzerzahlen und Lizenzgebühren zu kämpfen. Sie fragen sich vielleicht, wie diese neue Art der Lizenzierung funktioniert und welchen Nutzen sie Ihnen bringt. Vor allem wollen Sie sicherlich Ihr Budget einhalten und Kosten sparen, wo immer möglich. Das verstehen wir und wir möchten Ihnen dabei helfen!
Wir erklären Ihnen, wie Sie häufige Konfigurationsprobleme lösen können, die dazu führen können, dass mehr Benutzer gezählt werden als nötig, und wie Sie überflüssige oder ungenutzte Konten identifizieren und entfernen können, um Geld zu sparen. Es gibt auch einige Ansätze, die zu unnötigen Ausgaben führen können, z. B. wenn ein Personendokument anstelle eines Mail-Ins für geteilte Mailboxen verwendet wird. Wir zeigen Ihnen solche Fälle und deren Lösungen. Und natürlich erklären wir Ihnen das neue Lizenzmodell.
Nehmen Sie an diesem Webinar teil, bei dem HCL-Ambassador Marc Thomas und Gastredner Franz Walder Ihnen diese neue Welt näherbringen. Es vermittelt Ihnen die Tools und das Know-how, um den Überblick zu bewahren. Sie werden in der Lage sein, Ihre Kosten durch eine optimierte Domino-Konfiguration zu reduzieren und auch in Zukunft gering zu halten.
Diese Themen werden behandelt
- Reduzierung der Lizenzkosten durch Auffinden und Beheben von Fehlkonfigurationen und überflüssigen Konten
- Wie funktionieren CCB- und CCX-Lizenzen wirklich?
- Verstehen des DLAU-Tools und wie man es am besten nutzt
- Tipps für häufige Problembereiche, wie z. B. Team-Postfächer, Funktions-/Testbenutzer usw.
- Praxisbeispiele und Best Practices zum sofortigen Umsetzen
5th LF Energy Power Grid Model Meet-up SlidesDanBrown980551
5th Power Grid Model Meet-up
It is with great pleasure that we extend to you an invitation to the 5th Power Grid Model Meet-up, scheduled for 6th June 2024. This event will adopt a hybrid format, allowing participants to join us either through an online Mircosoft Teams session or in person at TU/e located at Den Dolech 2, Eindhoven, Netherlands. The meet-up will be hosted by Eindhoven University of Technology (TU/e), a research university specializing in engineering science & technology.
Power Grid Model
The global energy transition is placing new and unprecedented demands on Distribution System Operators (DSOs). Alongside upgrades to grid capacity, processes such as digitization, capacity optimization, and congestion management are becoming vital for delivering reliable services.
Power Grid Model is an open source project from Linux Foundation Energy and provides a calculation engine that is increasingly essential for DSOs. It offers a standards-based foundation enabling real-time power systems analysis, simulations of electrical power grids, and sophisticated what-if analysis. In addition, it enables in-depth studies and analysis of the electrical power grid’s behavior and performance. This comprehensive model incorporates essential factors such as power generation capacity, electrical losses, voltage levels, power flows, and system stability.
Power Grid Model is currently being applied in a wide variety of use cases, including grid planning, expansion, reliability, and congestion studies. It can also help in analyzing the impact of renewable energy integration, assessing the effects of disturbances or faults, and developing strategies for grid control and optimization.
What to expect
For the upcoming meetup we are organizing, we have an exciting lineup of activities planned:
-Insightful presentations covering two practical applications of the Power Grid Model.
-An update on the latest advancements in Power Grid -Model technology during the first and second quarters of 2024.
-An interactive brainstorming session to discuss and propose new feature requests.
-An opportunity to connect with fellow Power Grid Model enthusiasts and users.
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...Jason Yip
The typical problem in product engineering is not bad strategy, so much as “no strategy”. This leads to confusion, lack of motivation, and incoherent action. The next time you look for a strategy and find an empty space, instead of waiting for it to be filled, I will show you how to fill it in yourself. If you’re wrong, it forces a correction. If you’re right, it helps create focus. I’ll share how I’ve approached this in the past, both what works and lessons for what didn’t work so well.
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyScyllaDB
Freshworks creates AI-boosted business software that helps employees work more efficiently and effectively. Managing data across multiple RDBMS and NoSQL databases was already a challenge at their current scale. To prepare for 10X growth, they knew it was time to rethink their database strategy. Learn how they architected a solution that would simplify scaling while keeping costs under control.
In the realm of cybersecurity, offensive security practices act as a critical shield. By simulating real-world attacks in a controlled environment, these techniques expose vulnerabilities before malicious actors can exploit them. This proactive approach allows manufacturers to identify and fix weaknesses, significantly enhancing system security.
This presentation delves into the development of a system designed to mimic Galileo's Open Service signal using software-defined radio (SDR) technology. We'll begin with a foundational overview of both Global Navigation Satellite Systems (GNSS) and the intricacies of digital signal processing.
The presentation culminates in a live demonstration. We'll showcase the manipulation of Galileo's Open Service pilot signal, simulating an attack on various software and hardware systems. This practical demonstration serves to highlight the potential consequences of unaddressed vulnerabilities, emphasizing the importance of offensive security practices in safeguarding critical infrastructure.
Main news related to the CCS TSI 2023 (2023/1695)Jakub Marek
An English 🇬🇧 translation of a presentation to the speech I gave about the main changes brought by CCS TSI 2023 at the biggest Czech conference on Communications and signalling systems on Railways, which was held in Clarion Hotel Olomouc from 7th to 9th November 2023 (konferenceszt.cz). Attended by around 500 participants and 200 on-line followers.
The original Czech 🇨🇿 version of the presentation can be found here: https://www.slideshare.net/slideshow/hlavni-novinky-souvisejici-s-ccs-tsi-2023-2023-1695/269688092 .
The videorecording (in Czech) from the presentation is available here: https://youtu.be/WzjJWm4IyPk?si=SImb06tuXGb30BEH .
For the full video of this presentation, please visit: https://www.edge-ai-vision.com/2024/06/temporal-event-neural-networks-a-more-efficient-alternative-to-the-transformer-a-presentation-from-brainchip/
Chris Jones, Director of Product Management at BrainChip , presents the “Temporal Event Neural Networks: A More Efficient Alternative to the Transformer” tutorial at the May 2024 Embedded Vision Summit.
The expansion of AI services necessitates enhanced computational capabilities on edge devices. Temporal Event Neural Networks (TENNs), developed by BrainChip, represent a novel and highly efficient state-space network. TENNs demonstrate exceptional proficiency in handling multi-dimensional streaming data, facilitating advancements in object detection, action recognition, speech enhancement and language model/sequence generation. Through the utilization of polynomial-based continuous convolutions, TENNs streamline models, expedite training processes and significantly diminish memory requirements, achieving notable reductions of up to 50x in parameters and 5,000x in energy consumption compared to prevailing methodologies like transformers.
Integration with BrainChip’s Akida neuromorphic hardware IP further enhances TENNs’ capabilities, enabling the realization of highly capable, portable and passively cooled edge devices. This presentation delves into the technical innovations underlying TENNs, presents real-world benchmarks, and elucidates how this cutting-edge approach is positioned to revolutionize edge AI across diverse applications.
Driving Business Innovation: Latest Generative AI Advancements & Success StorySafe Software
Are you ready to revolutionize how you handle data? Join us for a webinar where we’ll bring you up to speed with the latest advancements in Generative AI technology and discover how leveraging FME with tools from giants like Google Gemini, Amazon, and Microsoft OpenAI can supercharge your workflow efficiency.
During the hour, we’ll take you through:
Guest Speaker Segment with Hannah Barrington: Dive into the world of dynamic real estate marketing with Hannah, the Marketing Manager at Workspace Group. Hear firsthand how their team generates engaging descriptions for thousands of office units by integrating diverse data sources—from PDF floorplans to web pages—using FME transformers, like OpenAIVisionConnector and AnthropicVisionConnector. This use case will show you how GenAI can streamline content creation for marketing across the board.
Ollama Use Case: Learn how Scenario Specialist Dmitri Bagh has utilized Ollama within FME to input data, create custom models, and enhance security protocols. This segment will include demos to illustrate the full capabilities of FME in AI-driven processes.
Custom AI Models: Discover how to leverage FME to build personalized AI models using your data. Whether it’s populating a model with local data for added security or integrating public AI tools, find out how FME facilitates a versatile and secure approach to AI.
We’ll wrap up with a live Q&A session where you can engage with our experts on your specific use cases, and learn more about optimizing your data workflows with AI.
This webinar is ideal for professionals seeking to harness the power of AI within their data management systems while ensuring high levels of customization and security. Whether you're a novice or an expert, gain actionable insights and strategies to elevate your data processes. Join us to see how FME and AI can revolutionize how you work with data!
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor IvaniukFwdays
At this talk we will discuss DDoS protection tools and best practices, discuss network architectures and what AWS has to offer. Also, we will look into one of the largest DDoS attacks on Ukrainian infrastructure that happened in February 2022. We'll see, what techniques helped to keep the web resources available for Ukrainians and how AWS improved DDoS protection for all customers based on Ukraine experience
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframePrecisely
Inconsistent user experience and siloed data, high costs, and changing customer expectations – Citizens Bank was experiencing these challenges while it was attempting to deliver a superior digital banking experience for its clients. Its core banking applications run on the mainframe and Citizens was using legacy utilities to get the critical mainframe data to feed customer-facing channels, like call centers, web, and mobile. Ultimately, this led to higher operating costs (MIPS), delayed response times, and longer time to market.
Ever-changing customer expectations demand more modern digital experiences, and the bank needed to find a solution that could provide real-time data to its customer channels with low latency and operating costs. Join this session to learn how Citizens is leveraging Precisely to replicate mainframe data to its customer channels and deliver on their “modern digital bank” experiences.
"Choosing proper type of scaling", Olena SyrotaFwdays
Imagine an IoT processing system that is already quite mature and production-ready and for which client coverage is growing and scaling and performance aspects are life and death questions. The system has Redis, MongoDB, and stream processing based on ksqldb. In this talk, firstly, we will analyze scaling approaches and then select the proper ones for our system.
How information systems are built or acquired puts information, which is what they should be about, in a secondary place. Our language adapted accordingly, and we no longer talk about information systems but applications. Applications evolved in a way to break data into diverse fragments, tightly coupled with applications and expensive to integrate. The result is technical debt, which is re-paid by taking even bigger "loans", resulting in an ever-increasing technical debt. Software engineering and procurement practices work in sync with market forces to maintain this trend. This talk demonstrates how natural this situation is. The question is: can something be done to reverse the trend?
1. 1 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
What is JDBC?
It is Java Database Connectivity technology.
This technology is an API(Application Programming Interface)
for the java programming language that define how
a client may access a database.
It provides methods for querying and updating data in database.
What are JDBC Drivers?
It is a software component enabling a java application to interact with a database.
JDBC Driver Types
JDBC drivers are divided into four types or levels. The different types of jdbc drivers are:
Type 1: JDBC-ODBC Bridge driver (Bridge)
Type 2: Native-API/partly Java driver (Native)
Type 3: AllJava/Net-protocol driver (Middleware)
Type 4: All Java/Native-protocol driver (Pure)
Type 1 JDBC Driver
JDBC-ODBC Bridge driver
The Type 1 driver translates all JDBC calls into ODBC calls and sends them to the ODBC
driver. ODBC is a generic API. The JDBC-ODBC Bridge driver is recommended only for
experimental use or when no other alternative is available.
2. 2 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
Type 1: JDBC-ODBC Bridge
Advantage
The JDBC-ODBC Bridge allows access to almost any database, since the database's ODBC
drivers are already available.
Disadvantages
1. This driver is not written fully in Java, Type 1 drivers are not portable.
2. A performance issue is seen as a JDBC call goes through the bridge to the ODBC driver,
then to the database, and this applies even in the reverse process. They are the slowest of
all driver types.
3. The client system requires the ODBC Installation to use the driver.
4. Not good for the Web.
3. 3 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
Type 2 JDBC Driver
Native-API/partly Java driver
The distinctive characteristic of type 2 jdbc drivers are
that Type 2 drivers convert JDBC calls into database-specific calls
i.e. this driver is specific to a particular database.
Some distinctive characteristic of type 2 jdbc drivers are shown below. Example: Oracle will
have oracle native api.
Type 2: Native api/ Partly Java Driver
4. 4 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
Advantage
The distinctive characteristic of type 2 jdbc drivers are that
they are typically offer better performance
than the JDBC-ODBC Bridge as the layers
of communication (tiers) are less than that of Type 1
and also it uses Native api which is Database specific.
Disadvantage
1. Native API must be installed in the Client System and hence type 2 drivers cannot be
used for the Internet.
3. This driver is not written in Java Language .Type 2 drivers are not portable.
4. If we change the Database we have to change
the native api as it is specific to a database.
5. Usually not thread safe.
Type 3 JDBC Driver
All Java/Net-protocol driver
Type 3 database requests are passed through
the network to the middle-tier server.
The middle-tier then translates the request to the database.
If the middle-tier server can in turn use Type1, Type 2 or Type 4 drivers.
5. 5 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
Type 3: All Java/ Net-Protocol Driver
Advantage
1. This driver is server-based, so there is no need for any vendor database library to be
present on client machines.
2. This driver is fully written in Java and hence it is Portable.
3. It is suitable for the web.
4. There are many opportunities to optimize portability,
performance, and scalability.
5. The net protocol can be designed to make
the client JDBC driver very small and fast to load.
6. This driver is very flexible allows access to multiple databases using one driver.
7. They are the most efficient amongst all driver types.
Disadvantage
6. 6 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
It requires another server application to install and maintain.
Type 4 JDBC Driver
Native-protocol/all-Java driver
The Type 4 uses java networking libraries
to communicate directly with the database server.
Type 4: Native-protocol/all-Java driver
Advantage
1.They are written in java so that it is portable.
2.It is most suitable for the web.
3. Number of translation layers is very less i.e. type 4 JDBC drivers don't have to translate
database requests to ODBC or a native connectivity interface or to pass the request on to another
server, performance is typically quite good.
3.It don’t need to install special software on the client or server. Further, these drivers can be
downloaded dynamically.
7. 7 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
Disadvantage
With type 4 drivers, the user needs a different driver for each database.
JDBC Architecture
The JDBC API supports both two-tier and three-tier processing models for database access.
1. Two-tier
In such an architecture, the Java application communicates directly with the data source (or
database). The database may reside on the same machine or may be on another machine to which
the clinet machine needs to be connected through a network
2. Three-tier
8. 8 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
In such an architecture, the client machine will send the database access statements to the
middleware, which will then send the statements to the database residing on the third tier of the
architecture, which is normally referred to as the back end. The statements will be processed
there and the result be returned back to the client through the middle tier. This approach will
have all the advantages associated with the 3-tier architecture, such as better maintainability,
easier deployment, scalability, etc.
BASIC JDBC STEPS
1.Load the driver
Loading Database driver is very first step towards making JDBC connectivity with the database.
It is necessary to load the JDBC drivers before attempting to connect to the database.
Syntax
Class.forName(drivername)
E.g
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”).
9. 9 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
2.Establishing Connection
After loading driver, now Establishing Connection with the database with user name and
password.
Syntax
con = DriverManager.getConnection(url+db, user, pass);
E.g
con = DriverManager.getConnection("jdbc:odbc:vision")
3.Create a statement object:
There are three basic types of SQL statements used in the JDBC API:
1.Statement:A Statement represents a general SQL statement without parameters. The method
createStatement() creates a Statement object.
Eg
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from student ");
2.Prepared Statement: A PreparedStatement represents a precompiled SQL statement, with
or without parameters. It is used for SQL commands that need to be executed repeatedly.
Eg 1
PreparedStatement ps = con.prepareStatement(“select * from student where rollno=?”);
ps.setString(1,1);
ResultSet rs = stmt.executeQuery();
Eg2
10. 10 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
PreparedStatement ps = con.prepareStatement(“insert into student values(?,?,?)”);
ps.setInt(1,1);
ps.setString(2,’amol’);
ps.setFloat(3,66.55f);
ResultSet rs = ps.executeUpdate();
3.CallableStatement - CallableStatement objects are used to execute SQL stored procedures
Eg
CallableStatement cstmt=conn.prepareCall(“call student”);
4.Execute a query
An SQL statement can either be a query that return result or operation that manipulates the
database
1.ResultSet executeQuery(String sql):
It is used for statements that return an output result(for only select query)
2.int executeUpdate(String sql): Returns an integer representing the number of rows affected
by the SQL statement. (For only INSERT, DELETE, or UPDATE SQL statements).
5.Process a query:ResultSet provides access to a table of data generated by executing a
Statement. The table rows are retrieved in sequence. A ResultSet maintains a cursor pointing to
its current row of data. The next() method is used to successively step through the rows of the
tabular results.
To access these values, there are getXXX() methods where XXX is a type for example,
getString(), getInt(),getFloat etc.
There are two forms of the getXXX methods:
i. Using columnName: getXXX(String columnName)
ii. Using columnNumber: getXXX(int columnNumber)
Example
11. 11 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
rs.getString(“stuname”));
rs.getString(1);
6.Close the connections
After all work is done, it is important to close the connection. But before the connection is
closed , close the ResultSet and the statement objects.
e.g
rs.close();
stmt.close();
conn.close();
Interface Description
CallableStatement The interface used to execute SQL stored
procedures.
Connection A connection (session) with a specific
database.
PreparedStatement An object that represents a precompiled SQL
statement.
ResultSet A table of data representing a database result
set, which is usually generated by executing
a statement that queries the database.
Statement The object used for executing a static SQL
statement and returning the results it
produces.
CallableStatement The interface used to execute SQL stored
procedures.
12. 12 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
ResultSet their Scroll Types
TYPE_FORWARD_ONLY The result set is not scrollable.
TYPE_SCROLL_INSENSITIVE The result set is scrollable but not sensitive to database
changes.
TYPE_SCROLL_SENSITIVE The result set is scrollable and sensitive to database
changes.
13. 13 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
1.Simple Program
import java.sql.*;
public class OdbcAccessConnection
{
public static void main(String [] args)
{
Connection con = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:vision");
System.out.println("Connection ok.");
con.close();
}
catch (Exception e)
{
System.err.println(“error”+e);
}
}
}
2.Using select Query
import java.sql.*;
public class OdbcAccessQuery
{
public static void main(String [] args)
{
Connection con = null;
try {
14. 14 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:visionstud");
Statement sta = con.createStatement();
ResultSet rs=sta.executeQuery("select * from student");
while(rs.next())
{
System.out.println("rollno"+rs.getInt(1));
System.out.println("name"+rs.getString(2));
System.out.println("Percentage"+rs.getFloat(3));
}
rs.close();
sta.close();
con.close();
}
catch (Exception e) {
System.err.println(“error”+e);
}
}
}
3 Insertion
import java.sql.*;
import java.io.*;
public class InsQuery
{
public static void main(String [] args)
{
Connection con = null;
try {
15. 15 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:visionstud");
Statement sta = con.createStatement();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Roll no: ");
int rno=Integer.parseInt(br.readLine());
System.out.println("Enter Name: ");
String name=br.readLine();
System.out.println("Enter percentage: ");
float per=Float.parseFloat(br.readLine());
String str="insert into student values("+rno+",'"+name+"',"+per+")";
int k=sta.executeUpdate(str);
if(k>0)
System.out.println("Insert "+k);
else
System.out.println("Insert "+k);
ResultSet rs=sta.executeQuery("select * from student");
while(rs.next())
{ System.out.println("rollno"+rs.getInt(1));
System.out.println("name"+rs.getString(2));
System.out.println("Percentage"+rs.getFloat(3));
}
rs.close();
sta.close();
con.close();
}
16. 16 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
catch (Exception e) {
System.err.println("Error"+e);
}
}
}
4.Update
import java.sql.*;
import java.io.*;
public class UpsQuery
{
public static void main(String [] args)
{
Connection con = null;
try {
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/vision", "root", "");
Statement sta = con.createStatement();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter roll no to update: ");
int rno=Integer.parseInt(br.readLine());
System.out.println("Enter name to update: ");
String name=br.readLine();
System.out.println("Enter percentage: ");
float per=Float.parseFloat(br.readLine());
String str="update student set name='"+name+"'"+","+"per="+per+" "+"where
rollno="+rno;
int k=sta.executeUpdate(str);
if(k>0)
System.out.println("Update "+k);
else
System.out.println("Update "+k);
ResultSet rs=sta.executeQuery("select * from student");
17. 17 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
while(rs.next())
{
System.out.println("rollno"+rs.getInt(1));
System.out.println("name"+rs.getString(2));
System.out.println("Percentage"+rs.getFloat(3));
}
rs.close();
sta.close();
con.close();
}
catch (Exception e) {
System.err.println("Exception: "+e);
}
}
}
5.Delete
import java.sql.*;
import java.io.*;
public class DelQuery
{
public static void main(String [] args)
{
Connection con = null;
try {
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/vision", "root", "");
Statement sta = con.createStatement();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter roll no to delete: ");
int rno=Integer.parseInt(br.readLine());
String str="Delete from student where rollno="+rno;
int k=sta.executeUpdate(str);
if(k>0)
System.out.println("Delete "+k);
else
18. 18 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
System.out.println("Delete "+k);
ResultSet rs=sta.executeQuery("select * from student");
while(rs.next())
{
System.out.println("rollno"+rs.getInt(1));
System.out.println("name"+rs.getString(2));
System.out.println("Percentage"+rs.getFloat(3));
}
rs.close();
sta.close();
con.close();
}
catch (Exception e)
{
System.err.println("Exception: "+e);
}
}
}
6.Searching
import java.sql.*;
import java.io.*;
public class SearchQuery
{
public static void main(String [] args)
{
Connection con = null;
try {
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/vision","root","");
Statement sta = con.createStatement();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter rno which U want to search.");
int rno=Integer.parseInt(br.readLine());
19. 19 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
String str="select * from student where rollno="+rno;
ResultSet rs=sta.executeQuery(str);
while(rs.next())
{
System.out.println("tRoll No: "+rs.getInt(1)+"ntName: "+rs.getString(2)+
"ntPercentage: "+ rs.getFloat(3));
}
rs.close();
sta.close();
con.close();
}
catch (Exception e) {
System.err.println("error "+e);
}
}
}
20. 20 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
MultiThreading
MuliProcessing
• This allows many processes to run simultaneously.
• Process is a running instance of the program. i.e. an operating system process.
CPU time is shared between different processes.
• OS provides context switching mechanism, which enables to switch between the
processes.
• Program’s entire contents (e.g. variables, global variables, functions) are stored
separately in their own context.
Example:- MS-Word and MS-Excel applications running simultaneously. (or any
two applications for that matter)
MultiThreading
• It allows many tasks within a program (process) to run simultaneously.
• Each such task is called as a Thread.
• Each Thread runs in a separate context.
• Each Thread has a beginning , a body,& an end
• Example:- Lets take a typical application like MS-Word. There are various independent
tasks going on, like displaying GUI, auto-saving the file, typing in text, spell-checking,
printing the file contents etc…
21. 21 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
Thread
• Thread is an independent sequential path of execution within a program. i.e.
separate call stack.
• Many threads run concurrently within a program.
• At runtime, threads in a program exist in a common memory space and can share both
data and code.
Start Start Start
Switching switching
How To Thread Created?
Threads can be achieved in one of the two ways –
1 Extending java.lang.Thread class.
2 Implementing java.lang.Runnable interface
1.Using Extending java.lang.Thread class.
To Define a class that extends Thread class & override its run() with code required by
thread.
Steps as Follows
Main Thread
Threads A Threads B Threads C
22. 22 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
1.Declare the class as extending the Thread class
Class Vision extends Thread
{
-----------
}
Where Vision is name of thread.
2.Implement the run() method.i.e Responsible for executing of code the thread will execute.
public void run()
{
-------
-----
}
3.Create a thread object & call the start() method to initiate the thread execution.
class A extends Thread
{
public void run()
{
for(int i=1;i<=5;i++)
{
System.out.println("n From Thread A:i="+i);
}
System.out.println("n Exit from A");
}
}
class B extends Thread
{
public void run()
{
23. 23 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
for(int j=1;j<=5;j++)
{
System.out.println("n From Thread B:j="+j);
}
System.out.println("n Exit from B");
}
}
class C extends Thread
{
public void run()
{
for(int k=1;k<=5;k++)
{
System.out.println("n From Thread C:k="+k);
}
System.out.println("n Exit from C");
}
}
class ThreadTest
{
public static void main(String args[])
{
A t1=new A();
//new A().start();
t1.start();//invoke run method
B t2=new B();
t2.start();//invoke run method
24. 24 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
C t3=new C();
t3.start();//invoke run method
}
}
2.Implementing java.lang.Runnable interface
Steps as follows
1.Declare the class as implementing the runnable interface.
2.Implement the run() method.
3.Create a thread by defining an object that is instantiated from “runnable” class as the
target of the thread.
4.Call the thread’s start() method to run the thread.
class A implements Runnable
{
public void run()
{
for(int i=1;i<=5;i++)
{
System.out.println("tThread A :"+i);
}
System.out.println("End of thread A");
}
}
class RunnableTest
{
public static void main(String args[])
{
25. 25 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
A r=new A();
Thread tx=new Thread(r);
tx.start();
System.out.println("End of main thread");
}
}
Life Cycle of thread
1. Newborn state
2. Runnable state
3. Running state
4. Blocked state
5. Dead state
newborn
Running
Runnable
Blocked
Dead
stop
stop
stop
Resume
Notify
Suspend
Sleep
wait
start
yield
Active
Thread
New
Thread
Idle
Thread
26. 26 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
1 Newborn state
It create a thread object, the thread is born & is said to be newborn state.
2. Runnable state
It means thread is ready for execution & is waiting for the availability of processor.
The processor of assigning time to threads is known as timing-slicing.
yield
……
Runnable thread
If a thread to leave control to another thread of equal priority before its turn comes,it can
done by using yield() method
3.Running state
It means that the processor has given its time to the thread for its execution.
The thread runs until it leaves control on its own or it is preempted by higher priority
thread.A running thread my leaves its control in one of the following
1.suspend():
It has been suspended using suspend() method. A suspended thread can be received by
using resume() method.
Resume()
Running Runable Suspended
27. 27 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
2.sleep()
It can put thread to sleep for a specified time period using sleep(t) method.(t is time
milliseconds).
Sleep(t)
After t
Running Runable Sleeping
3.wait()
It has been hold to wait until some event occurs. This is done using wait() method. The
thread can be scheduled to run again using notify() method.
Wait Notify()
Running Runable waiting
4.Blocked state
A thread is said to be blocked when it is prevented from entering into runnable state &
subsequently the running state. This happens when the thread is suspended,sleeping or waiting.
A blocked thread is considered “not runnable” but not dead .
5.Dead state
Every Thread has a life cycle. A running threads ends its life when it has completed executing its
run() method.
28. 28 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
Display the main Thread.
class CurrentThreadDemo
{
public static void main(String args[])
{
Thread t = Thread.currentThread();
System.out.println("Current thread: " + t);
// change the name of the thread
t.setName("My Thread");
System.out.println("After name change: " + t.getName());
try
{
for(int n = 6; n > 0; n--)
{
System.out.println(n);
}
}
catch (Exception e)
{
}
}
}
Threads priority
Each thread is assigned a priority, which affects the order it is scheduled for running.
i.e Threads are assigned priorities that the thread scheduler can use
to determine how the threads will be scheduled.
29. 29 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
The following static final integer constants are defined in the Thread class:
• MIN_PRIORITY =0( Lowest Priority)
• NORM_PRIORITY =5 (Default Priority)
• MAX_PRIORITY =10 (Highest Priority)
setPriority():It can modify a thread’s priority at any time after its creation using the
setPriority() method.
Threadname.setPriority(int number)
Where number is priority number.
getPriority(): It retrieve the thread priority value
class A extends Thread
{ public void run()
{
for(int i=1;i<=5;i++)
{
System.out.println("n From Thread A:i="+i);
}
System.out.println("n Exit from A");
}
}
class B extends Thread
{ public void run()
{
for(int j=1;j<=5;j++)
{ System.out.println("n From Thread B:j="+j);
}
System.out.println("n Exit from B");
}
}
30. 30 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
class C extends Thread
{ public void run()
{
for(int k=1;k<=5;k++)
{ System.out.println("n From Thread C:k="+k);
}
System.out.println("n Exit from C");
}
}
public class ThreadPriority
{ public static void main(String args[])
{
A t1=new A();
B t2=new B();
C t3=new C();
t3.setPriority(Thread.MAX_PRIORITY);
t1.setPriority(Thread.MIN_PRIORITY);
t3.start();
t1.start();
t2.start();
}
}
Threads Method
1. isAlive() method:
Returns true if the thread is alive, otherwise false.
public final boolean isAlive()
2.join() method:
31. 31 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
The join() method waits for a thread to die.(A thread to wait until the completion of
another thread before continue.
public void join()
class A extends Thread
{
public void run()
{
System.out.println("A Thread");
}
}
class B extends Thread
{
public void run()
{
System.out.println("B Thread");
}
}
class ThreadTest
{
public static void main(String args[])
{
try
{
A t1=new A();
t1.start();//invoke run method
32. 32 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
B t2=new B();
t2.start();//invoke run method
t1.join();
t2.join();
System.out.println("Main parent thread");
System.out.println("A thread "+t1.isAlive());
System.out.println("B thread "+t2.isAlive());
}
catch(Exception e)
{
System.out.println("error"+e);
}
}
}
What is mean by Synchronization?
When two or more threads need access to a shared resource,
they need to ensure that the resource will be used by only one thread at a time.
This process by which this is achieved is called Synchronization.
This is the general form of the synchronized statement:
synchronized method1 ()
{
// statements to be synchronized
}
33. 33 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
When it declare a method synchronized, Java creates a “Monitor” & hands it over to the
thread that calls the method first time. As long as the thread holds the monitor, no other thread
can enter the synchronized section of code.
When thread has completed its work of using synchronized method(or block of code),it
will hand over the monitor to the next thread that is ready to use same resource.
Using synchronized
class Callme
{
synchronized void call(String msg)
{
System.out.print("[" + msg);
System.out.println("]");
}
}
class Caller implements Runnable
{
String msg;
Callme target;
Thread t;
public Caller(Callme targ, String s)
{
target = targ;
msg = s;
t = new Thread(this);
t.start();
}
public void run()
{
34. 34 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
target.call(msg);
}
}
public class Synch
{
public static void main(String args[])
{
Callme target = new Callme();
Caller ob1 = new Caller(target, "Hello");
Caller ob2 = new Caller(target, "Synchronized");
Caller ob3 = new Caller(target, "World");
}
}
Java - Interthread Communication
When multiple threads are running in an application, it become necessary for the threads to
communicate(talk) with each other such communication called as interthread communication.
The thread can communicate by either sharing data or indicating when a specific activity has
completed.
Methods for interthread communication
wait( ): Causes the current thread to wait until another thread invokes the notify().
Notify( ): Wakes up a single thread that is waiting on this object's monitor.
notifyAll( ): Wakes up all the threads that called wait( ) on the same object.
Join():The join() method waits for a thread to die.(A thread to wait until the completion of
another thread before continue.
35. 35 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
Thread Method & Description
static Thread currentThread()
This method returns a reference to the currently
executing thread object.
String getName()
This method returns this thread's name.
int getPriority()
This method Returns this thread's priority.
boolean isAlive()
This method tests if this thread is alive.
void join()
Waits for this thread to die.
void run()
If this thread was constructed using a separate
Runnable run object, then that Runnable object's run
method is called; otherwise, this method does nothing
and returns
void setName(String name)
This method changes the name of this thread to be
equal to the argument name.
void setPriority(int newPriority)
This method changes the priority of this thread.
36. 36 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
static void sleep(long millis)
This method causes the currently executing thread to
sleep (temporarily cease execution) for the specified
number of milliseconds, subject to the precision and
accuracy of system timers and schedulers.
void start()
This method causes this thread to begin execution; the
Java Virtual Machine calls the run method of this
thread.
static void yield()
This method causes the currently executing thread
object to temporarily pause and allow other threads to
execute.
37. 37 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
NETWORKING
Networking Basics
Protocol
A protocol is a set of rules and standards for communication. A protocol specifies the
format of data being sent over the Internet, along with how and when it is sent. Three
important protocols used in the Internet are:
1. IP (Internet Protocol): is a network layer protocol that breaks data into small packets
and routes them using IP addresses.
2. TCP (Transmission Control Protocol): This protocol is used for connection-oriented
communication between two applications on two different machines. It is most reliable
and implements a connection as a stream of bytes from source to destination.
2. UDP (User Datagram Protocol): It is a connection less protocol
and used typically for
request and reply services. It is less reliable but faster than TCP.
Addressing
1. MAC Address: Each machine is uniquely identified by a physical address, address of
the network interface card. It is 48-bit address represented as 12 hexadecimal characters:
For Example: 00:09:5B:EC:EE:F2
3. IP Address: It is used to uniquely identify a network
and a machine in the network.
It
is referred as global addressing scheme.
Also called as logical address. Currently used
type of IP addresses is: Ipv4 – 32-bit address and Ipv6 – 128-bit address.
For Example:
Ipv4 – 192.168.16.1
Ipv6 – 0001:0BA0:01E0:D001:0000:0000:D0F0:0010
38. 38 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
4. Port Address: It is the address used in the network to
identify the application on the network.
Domain Name Service (DNS)
It is very difficult to remember the IP addresses of machines
in a network. Instead, we
can identify a machine using a “domain name”
which is character based naming
mechanism. Example: www.google.com.
The mapping between the domain name and the
IP address is done by a service called DNS.
URL
A URL (Uniform Resource Locator) is a unique identifier for any resource located on the
Internet. The syntax for URL is given as:
<protocol>://<hostname>[:<port>][/<pathname>][/<filename>[#<section>]]
Sockets
A socket represents the end-point of the network communication. It provides a simple
read/write interface and hides the implementation details network and transport layer
protocols. It is used to indicate one of the two end-points of a communication link
between two processes. When client wishes to make connection to a server, it will create
a socket at its end of the communication link.
The socket concept was developed in the first networked version of UNIX developed at
the University of California at Berkeley. So sockets are also known as Berkeley Sockets.
Ports
A port number identifies a specific application running in the machine.
A port number is a
number in the range 1-65535.
Reserved Ports: TCP/IP protocol reserves port number
in the range 1-1023 for the use of
specified standard services, often referred to as “well-known” services.
39. 39 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
The java.net Package
The java.net package provides classes and interfaces for implementing network
applications such as sockets, network addresses, Uniform Resource Locators (URLs) etc.
some important interfaces, classes and exceptions as follows :
InetAddress Class
Java InetAddress class represents an IP address. The java.net.InetAddress class provides
methods to get the IP of any host name for example www.google.com, www.facebook.com etc.
Method Description
public static InetAddress getByName(String
host) throws UnknownHostException
it returns the instance of InetAddress
containing LocalHost IP and name.
public static InetAddress getLocalHost()
throws UnknownHostException
it returns the instance of InetAdddress
containing local host name and address.
public String getHostName() it returns the host name of the IP
address.
public String getHostAddress() it returns the IP address in string format.
URL Class
As the name suggests, it provides a uniform way to locate resources on the web. Every
browser uses them to identify information on the web. The URL class provides a simple
API to access information across net using URLs.
The class has the following constructors:
1. URL(String url_str): Creates a URL object based on the string parameter. If the
URL cannot be correctly parsed, a MalformedURLException will be thrown.
2. URL(String protocol, String host, String path): Creates a URL object with the
specified protocol, host and path.
3. URL(String protocol, String host, int port, String path): Creates a URL object
with the specified protocol, host, port and file path.
4. URL(URL urlObj, String urlSpecifier): Allows you to use an existing URL as a
reference context and then create a new URL from that context.
40. 40 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
Method Description
public String getProtocol() it returns the protocol of the URL.
public String getHost() it returns the host name of the URL.
public String getPort() it returns the Port Number of the URL.
public String getFile() it returns the file name of the URL.
public URLConnection
openConnection()
it returns the instance of URLConnection i.e.
associated with this URL.
URLConnection Class
The Java URLConnection class represents a communication link between the URL and the
application. This class can be used to read and write data to the specified resource referred by the
URL.
public class URLConnectionExample
{
public static void main(String[] args)
{
try
{
URL url=new URL("http://www.visionacademe.com/java-tutorial");
URLConnection urlcon=url.openConnection();
InputStream stream=urlcon.getInputStream();
int i;
while((i=stream.read())!=-1)
{
System.out.print((char)i);
}
}catch(Exception e)
{
System.out.println(e);
}
}
}
Connection Oriented Communication
Using Socket Java performs the network communication. Sockets enables to transfer data
41. 41 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
through certain port. Socket class of Java makes it easy to write the socket program
Sockets are broken into two types:
1. Datagram sockets (UDP Socket)
1.A Datagram socket uses user datagram protocol (UDP) to send datagrams (self contained units
of information) in a connectionless manner.
2.This method does not guarantee delivery of the datagram.
3.The advantage is the datagram sockets require relatively few resources and so communication
is faster.
4.Typically request-reply types of application use datagram socket.
5.Java uses java.net.DatagramSocket class to create datagram socket. The
java.net.DatagramPacket represents a datagram.
2. Stream Socket (TCP Socket)
1.A stream socket is a “connected” socket through which data is transferred continuously.
2. It use TCP to create a connection between the client and server. TCP/IP sockets are used to
implement reliable, bidirectional, persistent, point to point, stream-based connection between
hosts on the internet.
3. The benefit of using a stream socket is the communication is reliable. because once
connected ,the communication link is available till it is disconnected. So data transmission is
done in real-time and data arrives reliably in the same order that it was sent. however this
requires more resource. Application like file transfer require a reliable communication. For such
application stream sockets are better.
4. Java uses java.net.Socket class to create stream socket for client and java.net.ServerSocket
for server.
Difference between Datagram and Stream socket
1.DatagramSocket is for sending UDP datagram
Stream socket is used for sending TCP packets.
42. 42 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
2. DatagramSocket is a packet based socket.
Stream socket is a byte oriented socket.
3. DatagramSocket are unreliable. They may be dropped ,duplicate and delivered out of order.
Stream socket is reliable ,if datas are lost on the way, TCP automatically re-sends.
4. DatagramSocket have less overheads and so faster.
Stream sockets require more overhead and are slower.
5.Application which use datagram sockets are request-reply type of application such as DNS
lookups,PING and SMTP.
Stream sockets are used for application like file transfer which require reliability.
6.For Datagram Socket used following class
java.net.DatagramSocket class
java.net.DatagramPacket class
For Stream Socket used following class
java.net.Socket class
java.net.ServerSocket class
7Datagram Socket uses connection less mechanism
Stream Socket uses connection oriented mechanism
ServerSocket Class
This class is used to create a server that listens for incoming connections from clients. It
is possible for client to connect with the server when server socket binds itself to a
specific port. The various constructors of the ServerSocket class are:
43. 43 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
1. ServerSocket(int port): binds the server socket to the specified port number. If 0 is
passed, any free port will be used. However, clients will be unable to access the
service unless notified the port number.
2. ServerSocket(int port, int numberOfClients): Binds the server socket to the
specified port number and allocates sufficient space to the queue to support the
specified number of client sockets.
3. ServerSocket(int port, int numberOfClients, InetAddress address): Binds the
server socket to the specified port number and allocates sufficient space to the queue
to support the specified number of client sockets and the IP address to which this
socket binds
The various methods of this class are:
Method Description
Socket Class
This class is used to represents a TCP client socket, which connects to a server socket and
initiate protocol exchanges. The various constructors of this class are:
1. Socket(InetAddress address, int port): creates a socket connected to the specified
IP address and port. Can throw an IOException.
44. 44 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
2. Socket(String host, int port): creates a socket connected to the specified host and
port. Can throw an UnknownHostException or an IOException.
How to create a server socket
1. Create a ServerSocket object which listen to a specific port.
2. Call the accept() method which accepts client request. This method return the client
socket object.
3. Use the socket object to communication with the client
import java.net.*;
import java.io.*;
public class Server
{
public static void main(String[] args)
45. 45 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
{
try
{
int port = 6666;
ServerSocket ss = new ServerSocket(port);
System.out.println("Waiting for a client...");
Socket socket = ss.accept();
InputStream sin = socket.getInputStream();
DataInputStream in = new DataInputStream(sin);
String line = null;
while(true)
{
line = in.readUTF();
System.out.println(“Receving line from client : " + line);
System.out.println();
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
How to create a client socket
1.Create an object of the socket class using the server names and port as parameter.
2.Communication with the server.
3.Close the socket
//Client
import java.net.*;
46. 46 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
import java.io.*;
public class Client
{
public static void main(String[] ar)
{
try
{
int serverPort = 6666;
String address = "127.0.0.1";
InetAddress ipAddress = InetAddress.getByName(address);
Socket socket = new Socket(ipAddress, serverPort);
OutputStream sout = socket.getOutputStream();
DataOutputStream out = new DataOutputStream(sout);
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
String line = null;
while(true)
{
line = keyboard.readLine();
System.out.println("Sending this line to the server...");
out.writeUTF(line); // send the above line to the server.
out.flush();
System.out.println();
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
47. 47 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
Servlet
What Web server?
➢ Apache is a very popular server
➢ 66% of the web sites on the Internet use Apache
Apache is:
• Full-featured and extensible
• Efficient
• Robust
• Secure (at least, more secure than other servers)
• Up to date with current standards
• Open source
• Free
What is Tomcat?
Tomcat is the Servlet Engine that handles servlet requests for Apache.
➢Tomcat is a “helper application” for Apache
➢It’s best to think of Tomcat as a “servlet container”
What is servlet?
A servlet is a web component,managed by a container, that generates dynamic content.
➢ Client sends a request to server
➢ Server starts a servlet
➢ Servlet computes a result for server and does not quit
➢ Server returns response to client
48. 48 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
➢ Another client sends a request
➢ Server calls the servlet again
The Life Cycle of a Servlet
1) Servlet class is loaded
The classloader is responsible to load the servlet class. The servlet class is loaded when the first
request for the servlet is received by the web container.
2) Servlet instance is created
The web container creates the instance of a servlet after loading the servlet class. The servlet
instance is created only once in the servlet life cycle.
3) init method is invoked
The web container calls the init method only once after creating the servlet instance.
The init method is used to initialize the servlet. It is the life cycle method of the
javax.servlet.Servlet interface. Syntax of the init method is given below:
public void init(ServletConfig config) throws ServletException
4) service method is invoked
The service() method of the Servlet is invoked to inform the Servlet about the client requests.
This method uses ServletRequest object to collect the data requested by the client.
49. 49 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
This method uses ServletResponse object to generate the output content.
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException
5) destroy method is invoked
When a servlet is unloaded by the servlet container, its destroy() method is called. This step is
only executed once, since a servlet is only unloaded once.
public void destroy()
The Servlet API
It includeTwo packages:
▪ javax.servlet
▪ javax.servlet.http
1.The javax.servlet Package
50. 50 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
The javax.servlet package contains a number of interfaces and classes that establish
the framework in which servlets operate.
Interface Description
Servlet Declares life cycle methods for a servlet.
ServletConfig Allows servlets to get initialization parameters.
ServletContext Enables servlets to log events and access
Information about their environment.
ServletRequest Used to read data from a client request.
ServletResponse Used to write data to a client response.
SingleThreadModel Indicates that the servlet is thread safe.
Class Description
GenericServlet Implements the Servlet and ServletConfig
interfaces.
ServletInputStream Provides an input stream for reading requests from a
client.
ServletOutputStream Provides an output stream for writing responses to a
client.
2.javax.servlet.http Package
Interface Description
HttpServletRequest Enables servlets to read data from an HTTP request.
HttpServletResponse Enables servlets to write data to an HTTP response.
HttpSession Allows session data to be read and written.
HttpSessionBindingListener Informs an object that it is bound to or unbound
from a session.
51. 51 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
Class Description
Cookie Allows state information to be stored on a client machine.
HttpServlet Provides methods to handle HTTP requests and responses.
1.doGet
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
Where
Input is from the HttpServletRequest parameter
Output is via the HttpServletResponse object, which we have named response
2.doPost
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
52. 52 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B> Hi Vision Academy!");
pw.close();
}
}
How to Run
Setting:
1.To install Apache tomcat software
2.Go to the browser(Internet explorer)
3.Start tomcat service.
& type the following URL in the Internet explorer(For Testing)
http://localhost:8080[The server listen to port 8080]
53. 53 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
1. To go to the following path
C:Program FilesApache Software FoundationTomcat 6.0lib
5 To copy the servlet-api & jsp-api file & paste to the following path
C:Program FilesJavajdk1.6.0jrelibext
1.To save above file(HelloServlet.java) following path
C:Program FilesApache Software FoundationTomcat 6.0webappsexamplesWEB-
INFclasses
2 Compile the servlet source code
javac HelloServlet.java
3 To go to the following path
C:Program FilesApache Software FoundationTomcat 6.0webappsexamplesWEB-INF
54. 54 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
4 Open the following file(web.xml)& enter the following entry in the file & save it.
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/servlets/servlet/HelloServlet</url-pattern>
</servlet-mapping>
5.To open internet explorer & type following URL
http://localhost:8080/examples/servlets/servlet/HelloServlet
How To retrieve value from the component
Using doGet method
<html>
<body>
55. 55 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
<center>
<form name="Form1"
method="get"
action="http://localhost:8080/examples/servlets/servlet/GetServlet">
Enter name
<input type=text name=”t”>
<br>
<input type=submit value="Submit">
</body>
</html>
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class GetServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String s = request.getParameter("t");
pw.println(s);
pw.close();
}
}
Using doPost method
<html>
<body>
<center>
<form name="Form1"
method="post"
action="http://localhost:8080/examples/servlets/servlet/PostServlet">
Enter name
56. 56 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
<input type=text name=”t”>
<br>
<input type=submit value="Submit">
</body>
</html>
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class PostServlet extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String s = request.getParameter("t");
pw.println(s);
pw.close();
}
}
2
<html>
<body>
<center>
<form name="Form1"
action="http://localhost:8080/examples/servlets/servlet/ColorGetServlet">
<B>Color:</B>
<select name="color" size="1">
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
</select>
57. 57 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
<br><br>
<input type=submit value="Submit">
</form>
</body>
</html>
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ColorGetServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String color = request.getParameter("color");
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B>The selected color is: ");
pw.println(color);
pw.close();
}
}
What is a Cookie?
A "cookie" is a small piece of information sent by a web server to store on a web browser so it
can later be read back from that browser. A cookie’s value identify user
Constructor of Cokkie class
Constructor Description
Cookie() constructs a cookie.
Cookie(String name, String value) constructs a cookie with a specified name and value.
Method of Cookie class
Method Description
public void setMaxAge(int Sets the maximum age of the cookie in seconds.
58. 58 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
expiry)
public String getName()
Returns the name of the cookie. The name cannot be changed
after creation.
public String getValue() Returns the value of the cookie.
public void setName(String
name)
changes the name of the cookie.
public void setValue(String
value)
changes the value of the cookie.
Interface Method Description
Public void addCookie(Cookie ck) method of HttpServletResponse interface is
used to add cookie in response object.
Public Cookie[] getCookies() method of HttpServletRequest interface is used
to return all the cookies from the browser.
Add cookie’s value
<html>
<body>
<center>
<form name="Form1"
method="post"
action="http://localhost:8080/examples/servlets/servlets/AddCookieServlet">
<B>Enter a value for MyCookie:</B>
<input type=textbox name="data" size=25 value="">
<input type=submit value="Submit">
</form>
</body>
</html>
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
SOFTWARE DEVELOPMENT
59. 59 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
USING JAVA
public class AddCookieServlet extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
// Get parameter from HTTP request.
String data = request.getParameter("data");
// Create cookie.
Cookie cookie = new Cookie("MyCookie", data);
// Add cookie to HTTP response.
//cookie.setMaxAge( 60 * 60 * 24 );//24 hours
response.addCookie(cookie);
// Write output to browser.
pw.println("<B>MyCookie has been set to");
pw.println(data);
pw.close();
}
}
Accessing cookie’s value
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class GetCookiesServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
// Get cookies from header of HTTP request.
Cookie[] cookies = request.getCookies();
for(int i = 0; i < cookies.length; i++)
{
60. 60 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
String name = cookies[i].getName();
String value = cookies[i].getValue();
pw.println("name = " + name +"; value = " + value);
}
pw.close();
}
}
Session Tracking
HTTP is a stateless protocol.
i.e Each request is independent of the previous one.In some applications,
it is necessary to save state information so that information can be collected from several
interactions between a browser and a server. Sessions provide
such a mechanism.
There are several ways through which it can provide unique identifier in request and response.
1. User Authentication – This is the very common way where we user can provide
authentication from the login page and then we can pass the authentication information
between server and client to maintain the session. This is not very effective method
because it wont work if the same user is logged in from different browsers.
2. HTML Hidden Field – We can create a unique hidden field in the HTML and when user
starts navigating, we can set its value unique to the user and keep track of the session.
This method can’t be used with links because it needs the form to be submitted every
time request is made from client to server with the hidden field. Also it’s not secure
because we can get the hidden field value from the HTML source and use it to hack the
session.
3. URL Rewriting – We can append a session identifier parameter with every request and
response to keep track of the session. This is very tedious because we need to keep track
of this parameter in every response and make sure it’s not clashing with other parameters.
4. Cookies: A "cookie" is a small piece of information sent by a web server to store on a
web browser so it can later be read back from that browser. It can maintain a session with
cookies but if the client disables the cookies, then it won’t work.
5. Session Management API:The servlet API provide methods and classes specifically
designed to handle session.The HttpSession class provide various session tracking
methods
61. 61 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
public void setAttribute( String name, Object value )
public Object getAttribute( String name )
public Object removeAttribute( String name )
USING JAA
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DateServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)throws ServletException, IOException
{
// Get the HttpSession object.
HttpSession hs = request.getSession(true);
// Get writer.
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String s = (String)hs.getAttribute("course");
if(s!= null)
{
hs.setAttribute("course", “bcs”);
}
else
pw.println("data is: " + s);
}
}
62. 62 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
JDBC USING SERVLET
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Jdconn extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
res.setContentType("text/html");
PrintWriter out = res.getWriter();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
63. 63 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
// Get a Connection to the database
con = DriverManager.getConnection("jdbc:odbc:vision2");
// Create a Statement object
stmt = con.createStatement();
// Execute an SQL query, get a ResultSet
rs = stmt.executeQuery("SELECT sname,address FROM stud");
while(rs.next())
{
out.println( rs.getString("sname") + " " + rs.getString("address"));
}
con.close();
}
catch(Exception e)
{
out.println(“error”+e);
}
}
}
JSP(Java Server Page)
• JSP is a server side program.
• JSP tags to enable dynamic content creation (Combination of HTML & JSP tag).
• JSP provide excellent server side scripting support for creating database driven web
applications
• JSP enable the developers to directly insert java code into jsp file, this makes the
development process very simple and its maintenance also becomes very easy.
• JSP pages are efficient, it loads into the web servers memory on receiving the request very
first time and the subsequent calls are served within a very short period of time.
There are 3 methods in JSP(Life cycle of JSP)
A JSP page undergoes 3 phases during life cycle.
1.Translation phase:In this phase,JSP pages get translated into servlet code.
64. 64 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
2.Compilation phase:In this phase, the servlet code compiled. The compilation is done only if
the page is requested the first time or it is modified.
3.Excution phase:This is final phase where jsp servlet methods are executed.These are
jspInit(),_jspService(),jspDestroy()
1.jspInt()
• This method is identical to the init() method in Java servlet.
• This method is called first when the JSP is requested and is used to initialize objects &
variables that are used throughout the life of the JSP.
public void jspInit()
{
// Initialization code...
}
2.jspDestroy()
• This method is identical to the destroy() method in Java servlet.
65. 65 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
• This method is automatically called when JSP terminates normally.
• This method is used for cleanup where resources used during execution of JSP are released.
public void jspDestroy()
{
// Your cleanup code goes here.
}
3._jspService()
• This method is automatically called & retrieves a connection to HTTP.
public void _jspService(HttpServletRequest request, HttpServletResponse response) {
// Service handling code...
}
JSP Architecture
66. 66 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
JSP Processing:
The following steps explain how the web server creates the web page using JSP:
• As with a normal page, your browser sends an HTTP request to the web server.
• The web server recognizes that the HTTP request is for a JSP page and forwards it to a
JSP engine. This is done by using the URL or JSP page which ends with .jsp instead of
.html.
• The JSP engine loads the JSP page from disk and converts it into a servlet content.
• The JSP engine compiles the servlet into an executable class and forwards the original
request to a servlet engine.
• A part of the web server called the servlet engine loads the Servlet class and executes it.
During execution, the servlet produces an output in HTML format, which the servlet
engine passes to the web server inside an HTTP response.
• The web server forwards the HTTP response to your browser in terms of static HTML
content.
JSP Tags
1.Comment Tags:
It is denoted by
<%--
--%>
67. 67 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
e.g
<%-- This comment will not be visible in the page source --%>
2.Declaration statement tags: This tag is used for defining the functions and variables to be
used in the JSP.
It is denoted by
<%!
%>
Eg
<%! int age=25;%>
3.Scriptlet tags: It is used for Java control statements & loop.
It is denoted by
<%
Eg. %>
<% for(int i=0;i<=3;i++)
{
---
---
}
%>
4.Expression tags: The expression is evaluated and the result is inserted into the HTML page
It is denoted by
<%= expression %>
Eg.
<%=age%>
5.Directive tags:
The jsp directives are messages that tells the web container how to translate a JSP page into the
corresponding servlet.
68. 68 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
There are three types of directives:
o page directive
o include directive
o taglib directive
1.page directive
The page directive defines attributes that apply to an entire JSP page.
It is denoted by
<%@ directive attribute="" %>
Attribute as follows
1.language: It defines the programming language (underlying language) being used in the page.
Syntax of language:
<%@ page language="value" %>
e.g
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
2.Extends: This attribute is used to extend (inherit) the class like JAVA does
Syntax of extends:
<%@ page extends="value" %>
e.g
<%@ page extends="demotest.DemoClass" %>
3.Import: It is used to import Java package into the JSP program.
Syntax of import:
69. 69 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
<%@ page import="value" %>
e.g
<%@page import=” java.sql.*” %
4.contentType:
• It defines the character encoding scheme i.e. it is used to set the content type and the
character set of the response
• The default type of contentType is "text/html; charset=ISO-8859-1".
Syntax of the contentType:
<%@ page contentType="value" %>
e.g
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
5.Session
Specifies whether or not the JSP page participates in HTTP sessionsSyntax of session
Syntax
<%@ page session="true/false"%>
e.g
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
session="false"%>
6.errorPage:
This attribute is used to set the error page for the JSP page if JSP throws an exception and then it
redirects to the exception page.
Syntax of errorPage:
<%@ page errorPage="value" %>
70. 70 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
e.g
<%@ page language="java" contentType="text/html;" pageEncoding="ISO-8859-1"
errorPage="errorHandler.jsp"%>
7. PageEncoding:
The "pageEncoding" attribute defines the character encoding for JSP page.The default is
specified as "ISO-8859-1" if any other is not specified.
Syntax
<%@ page pageEncoding="value" %>
Here value specifies the charset value for JSP
Example:
<%@ page language="java" contentType="text/html;" pageEncoding="ISO-8859-1"
isErrorPage="true"%>
2.include directive:
• include directive is used to include one file to the another file
• This included file can be HTML, JSP, text files, etc.
<%@ include file="/header.jsp" %>
e.g
a.jsp
<%="HELLO bcs"%>
p.jsp
<%@ include file="p.jsp" %>
<%="HELLO mcs"%>
3.taglib directive:
71. 71 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
JSP taglib directive is used to define the tag library with "taglib" as the prefix, which we can use
in JSP. (custom tags allows us to defined our own tags).
Syntax of taglib directive:
<%@ taglib uri="uri" prefix="value"%>
Here "uri" attribute is a unique identifier in tag library descriptor and "prefix" attribute is a tag
name.
e.g
<%@ taglib prefix="vtag" uri="http://java.sun.com/jsp/jstl/core" %>
How To run JSP?
<html>
<head>
<title>
Sachin Sir 9823037693
</title>
</head> JSP CODE
<body>
<%="HELLO Sachin Sir"%>
<body>
</html>
Step1 Save the file Hello.jsp into the following path
C:Program FilesApache Software FoundationTomcat 6.0webappsexamplesjsp
Step2 Open the browser & type it in the address bar
http://localhost:8080/examples/jsp/Hello.jsp
72. 72 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
Variables
It can declare your own variables, as usual
Using Function
<html>
<head>
<title>
Sachin Sir 9823037693 Sum of first n numbers
</title>
</head>
<body>
<%! int sumoffirst(int n)
{
int sum=0;
for(int i=1;i<=n;i++)
sum=sum+i;
return(sum);
}
%>
JSP CODE
<p>Sum of first n number:
</p>
<body>
</html>
<%=sumoffirst(5)%>
73. 73 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
JSP provides several predefined variables(implicit object)
Implicit object:These objects are created automatically by JSP container. It can directly use
these object.JSP Implicit Objects are also called pre-defined variables
No. Object & Description
1
request
This is the HttpServletRequest object associated
with the request.
2
response
This is the HttpServletResponse object associated
with the response to the client.
3
out
This is the PrintWriter object used to send output to
the client.
4
session
This is the HttpSession object associated with the
request.
5
application
This is the ServletContext object associated with the
application context.
6
config
This is the ServletConfig object associated with the
page.
7
pageContext
This encapsulates use of server-specific features like
higher performance JspWriters.
74. 74 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
8
page
This is simply a synonym for this, and is used to call
the methods defined by the translated servlet class.
9
Exception
The Exception object allows the exception data to be
accessed by designated JSP.
1.Display html & jsp page separate
l.html
<html>
<head>
<title>Login</title>
</head>
<body>
<form method="post" action="http://localhost:8080/examples/jsp/login.jsp">
Username:<input type="text" name="t1">
<br>
Password:<input type="password"name="t2">
<br>
<input type="submit" value="Login">
<input type="reset" value="Clear">
</body>
</html>
75. 75 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
Login.jsp
<%
String s1=request.getParameter("t1");
String s2=request.getParameter("t2");
if(s1.equals("sachin")&&s2.equals("sachin"))
out.println("Login Sucessfully");
else
out.println("Login incorrect");
%>
76. 76 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
Database connection using jsp
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<html>
<body>
<%
try
{
77. 77 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:visionstud");
Statement sta = con.createStatement();
ResultSet rs=sta.executeQuery("select * from student");
while(rs.next())
{
out.println("rollno"+rs.getInt(1));
out.println("name"+rs.getString(2));
out.println("Percentage"+rs.getFloat(3));
}
rs.close();
sta.close();
con.close();
}
catch(Exception e)
{
}
%>
</body>
</html>
78. 78 Vision Academy
(9822506209/9823037693 www.visionacademe.com)
(SACHIN SIR MCS In Scientific Computing From ISSC,UOP ,SET)
Classes For BCA/BBA(CA)/BCS/MCS/MC/MCS/BE(Comp)
Advance Java Note
JSP Benefits
• Easy to combine static templates,including HTML or XML.
• JSP pages compile dynamically into servlets.
• JSP makes it easier to author pages "by hand"
• JSP tags for invoking JavaBeansTM components
Compare servlet &jsp
JSP Servlets
JSP is a webpage scripting language that can generate
dynamic content.
Servlets are Java programs that are already
compiled which also creates dynamic web
content.
JSP run slower compared to Servlet as it takes
compilation time to convert into Java Servlets.
Servlets run faster compared to JSP.
It’s easier to code in JSP than in Java Servlets. Its little much code to write here.
In MVC, jsp act as a view. In MVC, servlet act as a controller.
JSP are generally preferred when there is not much
processing of data required.
servlets are best for use when there is more
processing and manipulation involved.
The advantage of JSP programming over servlets is that
we can build custom tags which can directly call Java
beans.
There is no such custom tag facility in servlets.
We can achieve functionality of JSP at client side by
running JavaScript at client side.
There are no such methods for servlets.
Vision Academy Since 2005
Prof. Sachin Sir(MCS,SET)
9822506209/9823037693
www.visionacademe.com
Branch1:Nr Sm Joshi College,Abv Laxmi zerox,Ajikayatara Build,Malwadi Rd,Hadapsar
Branch2:Nr AM College,Aditya Gold Society,Nr Allahabad Bank ,Mahadevnager