The document discusses Java Database Connectivity (JDBC) which provides a standard interface for connecting Java applications to various databases. It describes the JDBC architecture including common components like DriverManager, Connection, Statement, and ResultSet. It also explains the four types of JDBC drivers and how to register drivers, establish a connection, execute queries, and extract result sets in a JDBC application. Key classes like Connection, Statement, PreparedStatement, and ResultSet and their common methods are outlined.
JDBC (Java Database Connectivity) is a standard Java API for connecting to databases. It provides interfaces for tasks like making database connections, executing SQL statements, and retrieving results. There are 4 types of JDBC drivers that implement the JDBC interfaces in different ways. A basic JDBC program imports SQL packages, registers the JDBC driver, gets a database connection, executes SQL statements using a Statement object, extracts result data, and closes resources.
JDBC (Java Database Connectivity) is a standard Java API for connecting to databases. It provides interfaces for tasks like making database connections, executing SQL statements, and retrieving result sets. There are 4 types of JDBC drivers that implement the JDBC interfaces in different ways. A common JDBC application involves importing packages, registering the driver, getting a database connection, executing statements using that connection, and closing resources. Statements, PreparedStatements, and CallableStatements are used to send SQL/PLSQL commands and retrieve results.
JDBC (Java Database Connectivity) is a Java API that allows Java programs to connect to and interact with relational databases. There are four types of JDBC drivers: JDBC-ODBC bridge drivers, native-API drivers, network-protocol drivers, and database-protocol drivers. The key steps in using JDBC include: 1) loading the appropriate JDBC driver, 2) establishing a connection to the database, 3) creating statement objects to execute queries and updates, 4) executing the statements, 5) processing result sets, and 6) closing all open resources.
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 discusses various ways to interact with databases from Java programs using JDBC. It covers the main JDBC components like DriverManager, Connection, Statement, and ResultSet. It also describes the different types of JDBC drivers and their characteristics. The key steps to connect a Java application to a database are outlined as registering the driver, getting a connection, creating statements, executing queries, and closing the connection. Sample code is provided to demonstrate connecting to MySQL.
JDBC allows Java programs to execute SQL statements. It includes interfaces and classes that provide methods for connecting to a database, executing queries, processing result sets, and managing transactions. The key components of JDBC are the JDBC API, driver manager, drivers, and Java SQL package. There are four types of JDBC drivers: Type 1 uses JDBC-ODBC bridge, Type 2 uses a native database API, Type 3 uses a network protocol, and Type 4 communicates directly with a database via its network protocol. Creating a database connection in JDBC involves loading the driver, getting a connection, creating statements, executing queries, and closing resources.
The document discusses Java Database Connectivity (JDBC) which provides a standard interface for connecting Java applications to various databases. It describes the JDBC architecture including common components like DriverManager, Connection, Statement, and ResultSet. It also explains the four types of JDBC drivers and how to register drivers, establish a connection, execute queries, and extract result sets in a JDBC application. Key classes like Connection, Statement, PreparedStatement, and ResultSet and their common methods are outlined.
JDBC (Java Database Connectivity) is a standard Java API for connecting to databases. It provides interfaces for tasks like making database connections, executing SQL statements, and retrieving results. There are 4 types of JDBC drivers that implement the JDBC interfaces in different ways. A basic JDBC program imports SQL packages, registers the JDBC driver, gets a database connection, executes SQL statements using a Statement object, extracts result data, and closes resources.
JDBC (Java Database Connectivity) is a standard Java API for connecting to databases. It provides interfaces for tasks like making database connections, executing SQL statements, and retrieving result sets. There are 4 types of JDBC drivers that implement the JDBC interfaces in different ways. A common JDBC application involves importing packages, registering the driver, getting a database connection, executing statements using that connection, and closing resources. Statements, PreparedStatements, and CallableStatements are used to send SQL/PLSQL commands and retrieve results.
JDBC (Java Database Connectivity) is a Java API that allows Java programs to connect to and interact with relational databases. There are four types of JDBC drivers: JDBC-ODBC bridge drivers, native-API drivers, network-protocol drivers, and database-protocol drivers. The key steps in using JDBC include: 1) loading the appropriate JDBC driver, 2) establishing a connection to the database, 3) creating statement objects to execute queries and updates, 4) executing the statements, 5) processing result sets, and 6) closing all open resources.
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 discusses various ways to interact with databases from Java programs using JDBC. It covers the main JDBC components like DriverManager, Connection, Statement, and ResultSet. It also describes the different types of JDBC drivers and their characteristics. The key steps to connect a Java application to a database are outlined as registering the driver, getting a connection, creating statements, executing queries, and closing the connection. Sample code is provided to demonstrate connecting to MySQL.
JDBC allows Java programs to execute SQL statements. It includes interfaces and classes that provide methods for connecting to a database, executing queries, processing result sets, and managing transactions. The key components of JDBC are the JDBC API, driver manager, drivers, and Java SQL package. There are four types of JDBC drivers: Type 1 uses JDBC-ODBC bridge, Type 2 uses a native database API, Type 3 uses a network protocol, and Type 4 communicates directly with a database via its network protocol. Creating a database connection in JDBC involves loading the driver, getting a connection, creating statements, executing queries, and closing resources.
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.
This document provides an overview of Java Database Connectivity (JDBC). It discusses how JDBC allows Java programs to connect to and interact with databases. It describes the key components of JDBC, including the JDBC API, driver manager, drivers, and JDBC-ODBC bridge. It also covers basic SQL queries and how to install and set up JDBC.
This document discusses Java Database Connectivity (JDBC) and its components. It describes the two-tier and three-tier JDBC architectures. It explains the JDBC API and its interfaces like Driver, Connection, Statement, and ResultSet. It discusses the different types of JDBC drivers and provides examples of using JDBC to connect to a database, create statements, execute queries, retrieve results, and insert data using prepared statements.
This document discusses Java Database Connectivity (JDBC) and its components. It describes the two-tier and three-tier JDBC architectures. It explains the JDBC API and interfaces like Driver, Connection, Statement, and ResultSet. It also discusses the different types of JDBC drivers and provides code examples to connect to a database and execute queries using JDBC.
This document discusses Java Database Connectivity (JDBC) and its components. It describes the two-tier and three-tier JDBC architectures and the roles of the JDBC driver, connection, statement, and result set. It also covers the java.sql package, JDBC drivers, and steps for connecting to a database and executing queries using JDBC.
This document discusses Java Database Connectivity (JDBC) and its components. It describes the two-tier and three-tier JDBC architectures and the roles of the JDBC driver, connection, statement, and result set. It also covers the different types of JDBC drivers and provides code examples to demonstrate how to connect to a database and execute queries using JDBC.
JDBC provides a standard interface for connecting Java applications to different database systems. It allows Java programs to contain database-independent code. The key steps in a basic JDBC program are: 1) importing JDBC packages, 2) loading and registering the JDBC driver, 3) connecting to the database, 4) creating statements to execute queries, 5) executing queries and processing result sets, and 6) closing connections. JDBC supports different types of drivers including JDBC-ODBC bridge drivers, native API drivers, and pure Java drivers that communicate directly with databases.
JDBC provides a standard Java API for connecting Java applications to relational databases. It defines interfaces for establishing a connection to a database, sending SQL statements, processing results, and handling errors. There are four types of JDBC drivers that implement the API in different ways, including bridge drivers, native drivers, network protocol drivers, and pure Java drivers.
JDBC is a Java API that allows Java programs to connect to databases. It provides interfaces for establishing a connection to a database, executing SQL statements, and processing the results. There are four types of JDBC drivers that implement the connection between Java programs and databases in different ways, including using ODBC, native database APIs, network protocols, or thin drivers directly connecting to the database. The example shows how to use a JDBC-ODBC bridge driver to connect a Java program to a Microsoft Access database, running queries to retrieve and display records from a table.
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
The document discusses Java Database Connectivity (JDBC) and how it allows Java programs to connect to databases. It describes the four types of JDBC drivers, the core JDBC interfaces like Driver, Connection, and Statement, and how to use JDBC to perform CRUD operations. The key interfaces allow establishing a database connection and executing SQL statements to retrieve and manipulate data.
J2EE is a platform-independent Java-centric environment for developing, building, and deploying web-based enterprise applications. It consists of services, APIs, and protocols that provide functionality for developing multi-tier, web-based applications. J2EE supports component-based development of multi-tier enterprise applications consisting of client, web, EJB, and EIS tiers. Statements are used to send SQL commands and receive data from databases, with PreparedStatements being useful for queries with parameters and CallableStatements for stored procedures.
The document discusses Java Database Connectivity (JDBC). It describes JDBC as a Java API that allows Java programs to execute SQL statements. It provides methods for querying and updating data within a database. The document outlines the different components and specifications of JDBC, including the JDBC driver manager, JDBC drivers, and JDBC APIs. It also discusses the different types of JDBC drivers and their architectures.
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.
Java applications cannot directly communicate with a database to submit data and retrieve the results of queries.
This is because a database can interpret only SQL statements and not Java language statements.
For this reason, you need a mechanism to translate Java statements into SQL statements.
The JDBC architecture provides the mechanism for this kind of translation.
The JDBC architecture can be classified into two layers :
JDBC application layer.
JDBC driver layer.
JDBC application layer : Signifies a Java application that uses the JDBC API to interact with the JDBC drivers. A JDBC driver is software that a Java application uses to access a database. The JDBC driver manager of JDBC API connects the Java application to the driver.
JDBC driver layer : Acts as an interface between a Java applications and a database. This layer contains a driver , such as a SQL server driver or an Oracle driver , which enables connectivity to a database.
A driver sends the request of a Java application to the database. After processing the request, the database sends the response back to the driver. The driver translates and sends the response to the JDBC API. The JDBC API forwards it to the Java application.
JDBC is a Java API that allows Java programs to execute SQL statements. There are four types of JDBC drivers: Type 1 uses JDBC-ODBC bridge and ODBC driver; Type 2 uses a native database API; Type 3 uses a middleware layer for database independence; Type 4 communicates directly with the database using its native protocol. To connect to a database using JDBC, an application loads the appropriate JDBC driver and then calls DriverManager.getConnection(), specifying the database URL, username, and password.
JDBC provides a standard interface for connecting to and working with databases in Java applications. There are four main types of JDBC drivers: Type 1 drivers use ODBC to connect to databases but are only compatible with Windows. Type 2 drivers use native database client libraries but require the libraries to be installed. Type 3 drivers use a middleware layer to support multiple database types without native libraries. Type 4 drivers connect directly to databases using a pure Java implementation, providing cross-platform compatibility without additional layers.
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.
JDBC java for learning java for learn.pptkingkolju
The document discusses the common JDBC components used to connect to and interact with databases from Java programs. It describes the key interfaces and classes in JDBC including DriverManager, Driver, Connection, Statement, ResultSet, and SQLException. It provides an overview of how to establish a connection, execute SQL statements, and process the results using these JDBC components.
This document provides an introduction to JDBC (Java Database Connectivity) and how to connect to and query databases using JDBC. It discusses loading the appropriate JDBC driver, establishing a connection to the database using that driver, creating statements to execute queries, and processing the result sets returned by queries. It includes code examples to demonstrate connecting to a sample bikes database, executing a simple SELECT query, and iterating through the result set.
This document provides information about input and output in Java. It discusses files, streams, standard streams like System.in and System.out, and different ways of handling keyboard input in Java programs. The File class in Java represents files and directories on the disk. It describes the various File class constructors, methods, and examples of using the File class to work with files like creating, reading, and checking files. Standard streams provide predefined paths for input/output. Streams can be byte-based or character-based. Keyboard input can be handled using command line arguments, the Console class, Scanner class, or InputStreamReader class.
Control flow statements in programming include sequential, selection, and repetition statements. Selection statements, also called decision or branching statements, allow a program to test multiple conditions and execute code based on which conditions are true. Common selection statements include if, if-else, if-elif-else, and nested if statements. If statements run code when a single condition is met, if-else runs one code block if true and another if false, if-elif-else checks conditions sequentially, and nested if places an if inside another if.
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.
This document provides an overview of Java Database Connectivity (JDBC). It discusses how JDBC allows Java programs to connect to and interact with databases. It describes the key components of JDBC, including the JDBC API, driver manager, drivers, and JDBC-ODBC bridge. It also covers basic SQL queries and how to install and set up JDBC.
This document discusses Java Database Connectivity (JDBC) and its components. It describes the two-tier and three-tier JDBC architectures. It explains the JDBC API and its interfaces like Driver, Connection, Statement, and ResultSet. It discusses the different types of JDBC drivers and provides examples of using JDBC to connect to a database, create statements, execute queries, retrieve results, and insert data using prepared statements.
This document discusses Java Database Connectivity (JDBC) and its components. It describes the two-tier and three-tier JDBC architectures. It explains the JDBC API and interfaces like Driver, Connection, Statement, and ResultSet. It also discusses the different types of JDBC drivers and provides code examples to connect to a database and execute queries using JDBC.
This document discusses Java Database Connectivity (JDBC) and its components. It describes the two-tier and three-tier JDBC architectures and the roles of the JDBC driver, connection, statement, and result set. It also covers the java.sql package, JDBC drivers, and steps for connecting to a database and executing queries using JDBC.
This document discusses Java Database Connectivity (JDBC) and its components. It describes the two-tier and three-tier JDBC architectures and the roles of the JDBC driver, connection, statement, and result set. It also covers the different types of JDBC drivers and provides code examples to demonstrate how to connect to a database and execute queries using JDBC.
JDBC provides a standard interface for connecting Java applications to different database systems. It allows Java programs to contain database-independent code. The key steps in a basic JDBC program are: 1) importing JDBC packages, 2) loading and registering the JDBC driver, 3) connecting to the database, 4) creating statements to execute queries, 5) executing queries and processing result sets, and 6) closing connections. JDBC supports different types of drivers including JDBC-ODBC bridge drivers, native API drivers, and pure Java drivers that communicate directly with databases.
JDBC provides a standard Java API for connecting Java applications to relational databases. It defines interfaces for establishing a connection to a database, sending SQL statements, processing results, and handling errors. There are four types of JDBC drivers that implement the API in different ways, including bridge drivers, native drivers, network protocol drivers, and pure Java drivers.
JDBC is a Java API that allows Java programs to connect to databases. It provides interfaces for establishing a connection to a database, executing SQL statements, and processing the results. There are four types of JDBC drivers that implement the connection between Java programs and databases in different ways, including using ODBC, native database APIs, network protocols, or thin drivers directly connecting to the database. The example shows how to use a JDBC-ODBC bridge driver to connect a Java program to a Microsoft Access database, running queries to retrieve and display records from a table.
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
The document discusses Java Database Connectivity (JDBC) and how it allows Java programs to connect to databases. It describes the four types of JDBC drivers, the core JDBC interfaces like Driver, Connection, and Statement, and how to use JDBC to perform CRUD operations. The key interfaces allow establishing a database connection and executing SQL statements to retrieve and manipulate data.
J2EE is a platform-independent Java-centric environment for developing, building, and deploying web-based enterprise applications. It consists of services, APIs, and protocols that provide functionality for developing multi-tier, web-based applications. J2EE supports component-based development of multi-tier enterprise applications consisting of client, web, EJB, and EIS tiers. Statements are used to send SQL commands and receive data from databases, with PreparedStatements being useful for queries with parameters and CallableStatements for stored procedures.
The document discusses Java Database Connectivity (JDBC). It describes JDBC as a Java API that allows Java programs to execute SQL statements. It provides methods for querying and updating data within a database. The document outlines the different components and specifications of JDBC, including the JDBC driver manager, JDBC drivers, and JDBC APIs. It also discusses the different types of JDBC drivers and their architectures.
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.
Java applications cannot directly communicate with a database to submit data and retrieve the results of queries.
This is because a database can interpret only SQL statements and not Java language statements.
For this reason, you need a mechanism to translate Java statements into SQL statements.
The JDBC architecture provides the mechanism for this kind of translation.
The JDBC architecture can be classified into two layers :
JDBC application layer.
JDBC driver layer.
JDBC application layer : Signifies a Java application that uses the JDBC API to interact with the JDBC drivers. A JDBC driver is software that a Java application uses to access a database. The JDBC driver manager of JDBC API connects the Java application to the driver.
JDBC driver layer : Acts as an interface between a Java applications and a database. This layer contains a driver , such as a SQL server driver or an Oracle driver , which enables connectivity to a database.
A driver sends the request of a Java application to the database. After processing the request, the database sends the response back to the driver. The driver translates and sends the response to the JDBC API. The JDBC API forwards it to the Java application.
JDBC is a Java API that allows Java programs to execute SQL statements. There are four types of JDBC drivers: Type 1 uses JDBC-ODBC bridge and ODBC driver; Type 2 uses a native database API; Type 3 uses a middleware layer for database independence; Type 4 communicates directly with the database using its native protocol. To connect to a database using JDBC, an application loads the appropriate JDBC driver and then calls DriverManager.getConnection(), specifying the database URL, username, and password.
JDBC provides a standard interface for connecting to and working with databases in Java applications. There are four main types of JDBC drivers: Type 1 drivers use ODBC to connect to databases but are only compatible with Windows. Type 2 drivers use native database client libraries but require the libraries to be installed. Type 3 drivers use a middleware layer to support multiple database types without native libraries. Type 4 drivers connect directly to databases using a pure Java implementation, providing cross-platform compatibility without additional layers.
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.
JDBC java for learning java for learn.pptkingkolju
The document discusses the common JDBC components used to connect to and interact with databases from Java programs. It describes the key interfaces and classes in JDBC including DriverManager, Driver, Connection, Statement, ResultSet, and SQLException. It provides an overview of how to establish a connection, execute SQL statements, and process the results using these JDBC components.
This document provides an introduction to JDBC (Java Database Connectivity) and how to connect to and query databases using JDBC. It discusses loading the appropriate JDBC driver, establishing a connection to the database using that driver, creating statements to execute queries, and processing the result sets returned by queries. It includes code examples to demonstrate connecting to a sample bikes database, executing a simple SELECT query, and iterating through the result set.
Similar to java 4 Part 1 computer science.pptx (20)
This document provides information about input and output in Java. It discusses files, streams, standard streams like System.in and System.out, and different ways of handling keyboard input in Java programs. The File class in Java represents files and directories on the disk. It describes the various File class constructors, methods, and examples of using the File class to work with files like creating, reading, and checking files. Standard streams provide predefined paths for input/output. Streams can be byte-based or character-based. Keyboard input can be handled using command line arguments, the Console class, Scanner class, or InputStreamReader class.
Control flow statements in programming include sequential, selection, and repetition statements. Selection statements, also called decision or branching statements, allow a program to test multiple conditions and execute code based on which conditions are true. Common selection statements include if, if-else, if-elif-else, and nested if statements. If statements run code when a single condition is met, if-else runs one code block if true and another if false, if-elif-else checks conditions sequentially, and nested if places an if inside another if.
To create a query with criteria in MS Access:
1. Open the Query Design view and add the relevant table
2. Select the fields you want to include in the query
3. Add criteria to filter the results, such as only showing records where the name is "Jerry"
4. The query will then be run, displaying the records that match the criteria in the selected fields.
This document discusses various types of web hosting including shared hosting, dedicated hosting, and virtual private server hosting. It also covers related topics like buying hosting space, domain name registration, FTP client software, free hosting, content management systems, and responsive web design. Shared hosting is suitable for small websites with low traffic, while dedicated hosting provides exclusive server resources for high traffic websites. Virtual private servers provide a middle ground with dedicated bandwidth but less features than dedicated hosting. FTP clients allow file transfers between computers over the internet. Content management systems make website creation and management easier for non-technical users. Responsive web design adapts the layout to different screen sizes.
The document discusses loops and iteration in programming. It defines loops as a way to repeat certain tasks a set number of times, like printing attendance for each student in a class. There are two main types of loops: conditional loops, which repeat until a condition is met, and counting loops, which repeat a set number of times. The document focuses on for loops, explaining that they iterate over a sequence, executing the loop body for each item. It provides an example of using a for loop to print even numbers from a list. It also discusses the range() function for generating sequences of numbers to iterate over.
Conditional statements control the flow of programs. There are three types: sequential, selection, and repetition. Selection statements include if, if-else, and if-elif-else. If runs code when a condition is true. If-else runs one code block if true, another if false. If-elif-else checks multiple conditions sequentially. Nested if places an if statement inside another if to check multiple levels of conditions. These statements allow programs to make decisions and branch based on different conditions being true.
Exceptions, I/O and Threads Input and Output in Java: The File Class, Standard Streams, Keyboard
Input, File I/O Using Byte Streams, Character Streams, File I/O Using Character Streams -
Buffered Streams, File I/O Using a Buffered Stream, Keyboard Input Using a Buffered Stream,Writing Text Files. Threads: Threads vs. Processes, Creating Threads by Extending Thread,
Creating Threads by Implementing Runnable, Advantages of Using Threads, Daemon Threads,
Thread States, Thread Problems, Synchronization. Exceptions: Exception Handling, The Exception
Hierarchy, throws statement, throw statement, Developing user defined Exception Classes- The
finally Block.
Introduction to Java: History, Versioning, The Java Virtual Machine, Byte code, Writing simple
java program, Language Components: Primitive Data Types, Comments, Keywords, literals, The
break Statement, The continue Statement, Operators – Casts and Conversions, Arrays. Introduction
to classes and methods, constructors, Passing Objects to Methods, Method Overloading, Static and
final, The this Reference, finalize, inner and nested classes. Inheriting class, extends, member
access and inheritance, super keyword, Object class. Dynamic method dispatch, method overriding,
abstract class, interface, packages, import statement
Introduction to OOPS, Characteristics of OOPS, Object oriented languages, comparison between
procedural and object oriented programming, basic principles of Object Orientation-class, object,
abstraction, encapsulation, inheritance, polymorphism, modularity, and message passing. Features
of object orientation - attributes, state, identity, operation, behaviour.
Arrays are a collection of elements of the same type stored in contiguous memory locations. An array is declared with a type, name and size. Individual elements can be accessed using an index from 0 to size-1. Arrays can be initialized during declaration. Common operations on arrays include traversing elements using a for loop, calculating sum and average of elements, and treating strings as character arrays.
This document discusses the different scopes of variables in PHP - local, global, and static. Local variables can only be accessed within their declared function. Global variables are accessible from any part of a script outside of functions. The global keyword allows access to global variables from within functions. Static variables retain their value between function calls, unlike local variables which are deleted after each call.
Var_dump and print_r are PHP functions used to output structured information about arrays and objects. Var_dump shows the type and value of variables and explores arrays recursively with indentation to show structure. Print_r displays array values in a human-readable format with keys and elements. Both functions can output the properties of an object created from an array, with print_r using a stdClass Object notation and var_dump providing more detail on types.
The document discusses different database concepts:
1) A database is a collection of organized data that can be easily retrieved, inserted, and deleted. Database management systems (DBMS) like MySQL and Oracle are software used to manage databases.
2) The two main data models are the relational model, which organizes data into tables and relations, and the object-oriented model, which represents data as objects with properties and methods.
3) DBMS provide advantages like data sharing, backup/recovery, security, and independence between data and applications. However, they also have disadvantages such as higher costs and complexity.
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...IJECEIAES
Medical image analysis has witnessed significant advancements with deep learning techniques. In the domain of brain tumor segmentation, the ability to
precisely delineate tumor boundaries from magnetic resonance imaging (MRI)
scans holds profound implications for diagnosis. This study presents an ensemble convolutional neural network (CNN) with transfer learning, integrating
the state-of-the-art Deeplabv3+ architecture with the ResNet18 backbone. The
model is rigorously trained and evaluated, exhibiting remarkable performance
metrics, including an impressive global accuracy of 99.286%, a high-class accuracy of 82.191%, a mean intersection over union (IoU) of 79.900%, a weighted
IoU of 98.620%, and a Boundary F1 (BF) score of 83.303%. Notably, a detailed comparative analysis with existing methods showcases the superiority of
our proposed model. These findings underscore the model’s competence in precise brain tumor localization, underscoring its potential to revolutionize medical
image analysis and enhance healthcare outcomes. This research paves the way
for future exploration and optimization of advanced CNN models in medical
imaging, emphasizing addressing false positives and resource efficiency.
Design and optimization of ion propulsion dronebjmsejournal
Electric propulsion technology is widely used in many kinds of vehicles in recent years, and aircrafts are no exception. Technically, UAVs are electrically propelled but tend to produce a significant amount of noise and vibrations. Ion propulsion technology for drones is a potential solution to this problem. Ion propulsion technology is proven to be feasible in the earth’s atmosphere. The study presented in this article shows the design of EHD thrusters and power supply for ion propulsion drones along with performance optimization of high-voltage power supply for endurance in earth’s atmosphere.
Advanced control scheme of doubly fed induction generator for wind turbine us...IJECEIAES
This paper describes a speed control device for generating electrical energy on an electricity network based on the doubly fed induction generator (DFIG) used for wind power conversion systems. At first, a double-fed induction generator model was constructed. A control law is formulated to govern the flow of energy between the stator of a DFIG and the energy network using three types of controllers: proportional integral (PI), sliding mode controller (SMC) and second order sliding mode controller (SOSMC). Their different results in terms of power reference tracking, reaction to unexpected speed fluctuations, sensitivity to perturbations, and resilience against machine parameter alterations are compared. MATLAB/Simulink was used to conduct the simulations for the preceding study. Multiple simulations have shown very satisfying results, and the investigations demonstrate the efficacy and power-enhancing capabilities of the suggested control system.
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...IJECEIAES
Climate change's impact on the planet forced the United Nations and governments to promote green energies and electric transportation. The deployments of photovoltaic (PV) and electric vehicle (EV) systems gained stronger momentum due to their numerous advantages over fossil fuel types. The advantages go beyond sustainability to reach financial support and stability. The work in this paper introduces the hybrid system between PV and EV to support industrial and commercial plants. This paper covers the theoretical framework of the proposed hybrid system including the required equation to complete the cost analysis when PV and EV are present. In addition, the proposed design diagram which sets the priorities and requirements of the system is presented. The proposed approach allows setup to advance their power stability, especially during power outages. The presented information supports researchers and plant owners to complete the necessary analysis while promoting the deployment of clean energy. The result of a case study that represents a dairy milk farmer supports the theoretical works and highlights its advanced benefits to existing plants. The short return on investment of the proposed approach supports the paper's novelty approach for the sustainable electrical system. In addition, the proposed system allows for an isolated power setup without the need for a transmission line which enhances the safety of the electrical network
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELijaia
As digital technology becomes more deeply embedded in power systems, protecting the communication
networks of Smart Grids (SG) has emerged as a critical concern. Distributed Network Protocol 3 (DNP3)
represents a multi-tiered application layer protocol extensively utilized in Supervisory Control and Data
Acquisition (SCADA)-based smart grids to facilitate real-time data gathering and control functionalities.
Robust Intrusion Detection Systems (IDS) are necessary for early threat detection and mitigation because
of the interconnection of these networks, which makes them vulnerable to a variety of cyberattacks. To
solve this issue, this paper develops a hybrid Deep Learning (DL) model specifically designed for intrusion
detection in smart grids. The proposed approach is a combination of the Convolutional Neural Network
(CNN) and the Long-Short-Term Memory algorithms (LSTM). We employed a recent intrusion detection
dataset (DNP3), which focuses on unauthorized commands and Denial of Service (DoS) cyberattacks, to
train and test our model. The results of our experiments show that our CNN-LSTM method is much better
at finding smart grid intrusions than other deep learning algorithms used for classification. In addition,
our proposed approach improves accuracy, precision, recall, and F1 score, achieving a high detection
accuracy rate of 99.50%.
Embedded machine learning-based road conditions and driving behavior monitoringIJECEIAES
Car accident rates have increased in recent years, resulting in losses in human lives, properties, and other financial costs. An embedded machine learning-based system is developed to address this critical issue. The system can monitor road conditions, detect driving patterns, and identify aggressive driving behaviors. The system is based on neural networks trained on a comprehensive dataset of driving events, driving styles, and road conditions. The system effectively detects potential risks and helps mitigate the frequency and impact of accidents. The primary goal is to ensure the safety of drivers and vehicles. Collecting data involved gathering information on three key road events: normal street and normal drive, speed bumps, circular yellow speed bumps, and three aggressive driving actions: sudden start, sudden stop, and sudden entry. The gathered data is processed and analyzed using a machine learning system designed for limited power and memory devices. The developed system resulted in 91.9% accuracy, 93.6% precision, and 92% recall. The achieved inference time on an Arduino Nano 33 BLE Sense with a 32-bit CPU running at 64 MHz is 34 ms and requires 2.6 kB peak RAM and 139.9 kB program flash memory, making it suitable for resource-constrained embedded systems.
Discover the latest insights on Data Driven Maintenance with our comprehensive webinar presentation. Learn about traditional maintenance challenges, the right approach to utilizing data, and the benefits of adopting a Data Driven Maintenance strategy. Explore real-world examples, industry best practices, and innovative solutions like FMECA and the D3M model. This presentation, led by expert Jules Oudmans, is essential for asset owners looking to optimize their maintenance processes and leverage digital technologies for improved efficiency and performance. Download now to stay ahead in the evolving maintenance landscape.
1. UNIT 4 part 1
Database Connectivity
JAVA
Muhammed Mashahil P
2. ❏ JDBC is Java application programming interface that allows the Java
programmers to access database management system from the java
code.
❏ It was developed by JavaSoft, a subsidiary of Sun Microsystems.
❏ It is a java API which enables the java programs to execute SQL
statements
❏ JDBC provides methods for querying and updating the data in Relational
Database Management system such as SQL, Oracle etc.
❏ Generally all Relational Database Management System supports SQL
and we all know that Java is platform independent.
❏ So JDBC makes it possible to write a single database application that
can run on different platforms and interact with different Database
Management Systems.
JDBC?
3. ❏ JDBC stands for Java Database Connectivity. JDBC is a Java API to
connect and execute the query with the database.
❏ It is a part of JavaSE (Java Standard Edition). JDBC API uses JDBC
drivers to connect with the database.
JDBC?
4. ODBC (Open Data Base Connectivity)
❏ Open DataBase Connectivity is similar to Java Database Connectivity which
is used for accessing and managing database,
❏ but the difference is that JDBC is designed specifically for Java programs,
whereas ODBC is not depended upon any language
5. The JDBC-ODBC bridge
❏ The JDBC-ODBC bridge, also known as JDBC type 1 driver is a database
driver that utilize the ODBC driver to connect the database.
❏ This driver translates JDBC method calls into ODBC function calls.
❏ The Bridge implements Jdbc for any database for which an Odbc driver is
available.
❏ The Bridge is always implemented as the sun.jdbc.odbc Java package and it
contains a native library used to access ODBC.
6. ❏ There are four types of JDBC drivers:
❏ JDBC-ODBC Bridge Driver,
❏ Native Driver,
❏ Network Protocol Driver, and
❏ Thin Driver
7. 1) JDBC-ODBC bridge driver
❏ The JDBC-ODBC bridge driver uses ODBC driver to connect to the database. The JDBC-ODBC
bridge driver converts JDBC method calls into the ODBC function calls.
❏ This is now discouraged because of thin driver.
❏ Oracle does not support the JDBC-ODBC Bridge from Java 8. Oracle recommends that you use
JDBC drivers provided by the vendor of your database instead of the JDBC-ODBC Bridge.
❏ Advantages:
❏ easy to use.
❏ can be easily connected to any database.
❏ Disadvantages:
❏ Performance degraded because JDBC method call is
converted into the ODBC function calls.
❏ The ODBC driver needs to be installed on the client
machine.
8. 2) Native-API driver
❏ The Native API driver uses the client-side libraries of the database. The driver converts JDBC
method calls into native calls of the database API. It is not written entirely in java..
Advantages:
❏ performance upgraded than JDBC-ODBC bridge driver.
Disadvantages:
❏ The Native driver needs to be installed on the each client machine.
❏ The Vendor client library needs to be installed on client machine.
9. 3) Network Protocol driver
❏ The Network Protocol driver uses middleware (application server) that converts JDBC calls
directly or indirectly into the vendor-specific database protocol. It is fully written in java.
Advantages:
#No client side library is required because of application server that can perform many tasks like auditing,
load balancing, logging etc.
Disadvantages:
#Network support is required on client machine.
#Requires database-specific coding to be done in the middle tier.
#Maintenance of Network Protocol driver becomes costly because it requires database-specific coding to be
done in the middle tier.
10. 4) Thin driver
❏ The thin driver converts JDBC calls directly into the vendor-specific database protocol. That is
why it is known as thin driver. It is fully written in Java language.
Advantages:
#Better performance than all other drivers.
#No software is required at client side or server side.
Disadvantages:
#Drivers depend on the Database
11. JDBC
❏ The JDBC API supports both two-tier and three-tier models for database
access.
❏ Two-tier model -- a Java applet or application interacts directly with the
database.
❏ Three-tier model -- introduces a middle-level server for execution of
business logic:
❏ the middle tier to maintain control over data access.
❏ the user can employ an easy-to-use higher-level API which is translated by
the middle tier into the appropriate low-level calls.
13. JDBC API
❏ The JDBC API provides the facility for accessing the relational database from the
Java programming language.
❏ The user not only execute the SQL statements, retrieve results, and update the
data but can also access it anywhere within a network because of it's "Write Once,
Run Anywhere" (WORA) capabilities.
❏ Due to JDBC API technology, user can also access other tabular data sources
like spreadsheets or flat files even in the a heterogeneous environment.
❏ JDBC application programming interface is a part of the Java platform that have
included Java SE and Java EE in itself.
❏ The latest version of JDBC 4.0 application programming interface is divided into
two packages.
i) java.sql.
ii) javax.sql.
❏ Java SE and Java EE platforms are included in both the packages.
14. JDBC Driver Manager
❏ The JDBC Driver Manager is a very important class that defines objects
which connect Java applications to a JDBC driver.
❏ Usually Driver Manager is the backbone of the JDBC architecture.
❏ It's very simple and small that is used to provide a means of managing the
different types of JDBC database driver running on an application
❏ The main responsibility of JDBC database driver is to load all the drivers
found in the system properly as well as to select the most appropriate driver
from opening a connection to a database.
❏ The Driver Manager also helps to select the most appropriate driver from the
previously loaded drivers when a new open database is connected.
15. JDBC Driver Manager (contn)
❏ The function of JDBC driver test suite is to make ensure that the JDBC
drivers will run user's program or not .
❏ The test suite of JDBC application program interface is very useful for testing
a driver based on JDBC technology during testing period.
❏ It ensures the requirement of Java Platform Enterprise Edition (J2EE).
16. Database
A Database is a collection of related data organised in a way that data can be easily
accessed, managed and updated. Database can be software based or hardware based, with
one sole purpose, storing data.
DBMS
A DBMS is a software that allows creation, definition and manipulation of database, allowing
users to store, process and analyse data easily. DBMS provides us with an interface or a
tool, to perform various operations like creating database, storing data in it, updating data,
creating tables in the database and a lot more.
DBMS also provides protection and security to the databases. It also maintains data
consistency in case of multiple users.
Here are some examples of popular DBMS used these days:
- MySql
- Oracle
- SQL Server
- IBM DB2
17. SQL Package
❏ Provides the API for accessing and processing data stored in a data source
(usually a relational database) using the Java programming language.
❏ This API includes a framework whereby different drivers can be installed
dynamically to access different data sources.
❏ Although the JDBCTM API is mainly geared to passing SQL statements to a
database, it provides for reading and writing data from any data source with a
tabular format.
❏ The reader/writer facility, available through the javax.sql.RowSet group of
interfaces, can be customized to use and update data from a spread sheet, or
any other tabular data source
18. CONTENTS OF SQL PACKAGE
❏ The java.sql package contains API for the following:
1. Making a connection with a database via the DriverManager facility
19. CONTENTS OF SQL PACKAGE
2. Sending SQL statements to a database
3. Retrieving and updating the results of a query
- ResultSet interface Class or Interface
20. CONTENTS OF SQL PACKAGE
4. Standard mappings for SQL types to classes and interfaces in the Java
programming language
21. CONTENTS OF SQL PACKAGE
5. Custom mapping an SQL user-defined type (UDT) to a class in the Java
6. Metadata
24. DriverManager Class
Following are the methods of DriverManager class:
1. deregisterDriver(Driver driver) : It drops the driver from the list of drivers
registered in the DriverManager class.
2. registerDriver(Driver driver) :It registers the driver with the DriverManager class.
3. getConnection(String url) : It tries to establish the connection to a given
database URL.
4. getConnection(String url, String user, String password) : It tries to establish
the connection to a given database URL.
5. getConnection(String url, Properties info) : It tries to establish the connection
to a given database URL.
6. getDriver(String url) : It attempts to locate the driver by the given string.
7. getDrivers() : It retrieves the enumeration of the drivers which has been
registered with the DriverManager class.
25. SEVEN BASIC STEPS IN ESTABLISHING CONNECTION WITH DATABASE
1. Import package
2. Load and register the driver.
3. Establish the Connection.
4. Create a Statement object.
5. Execute a Query.
6. Process the results.
7. Close the connection.
26. STEP 1-Import package
- java.sql:
Provides the API for accessing and processing data stored in a data source
(usually a relational database) using the JavaTM programming language.This API
includes a framework whereby different drivers can be installed dynamically to
access different data sources. Although the JDBCTM API is mainly geared to
passing SQL statements to a database, it provides for reading and writing data
from any data source with a tabular format.
- javax.sql:
Provides the API for server side data source access and processing from the
JavaTM programming language. This package supplements the java.sql package
and, as of the version 1.4 release, is included in the Java Platform, Standard
Edition (Java SETM). It remains an essential part of the Java Platform, Enterprise
Edition (Java EETM).The reader/writer facility, available through the
javax.sql.RowSet group of interfaces, can be customized to use and update data
from a spread sheet, flat file, or any other tabular data source
27. STEP 2-Load and register the driver
A. Load Driver
- Which driver loads based on which database we are going to connecting with
Eg:- For mysql
com.mysql.jdbc.Driver
- To load the driver we have to Download it
Eg:- For mysql
Mysql connector from mysql website
A. Register Driver
- To register we have to use method forName()
Eg:-
Syntax of Class.forName() method:
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
For mysql
class.forName(“com.mysql.jdbc.Driver”);
28. STEP 3-Establish connection
- After registering and loading the driver,
- we will create a connection using getConnection() method of DriverManager class.
- This method has several overloaded methods that can be used based on the requirement.
- Basically it require the database name, username and password to establish connection.
Syntax
getConnection(String url)
getConnection(String url, String username, String password)
getConnection(String url, Properties info)
For Example:-
Connection con = DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:XE","usrnme", "password");
29. STEP 4- Create SQL Statement
❏ You need to create a Statement object to send requests to and retrieve
results from a database.
❏ The Connection object provides the createStatement () method to create a
Statement object.
❏ It is used to execute the sql queries and defined in Connection class.
Syntax of the method is given below.
public Statement createStatement() throws SQLException
Example to create a SQL statement
Statement s=con.createStatement();
30. STEP 5- Execute SQL Statement
❏ After creating statement, now execute using executeQuery() method of
Statement interface.
❏ This method is used to execute SQL statements. Syntax of the method is
given below.
Syntax of the method is given below.
public ResultSet executeQuery(String query) throws SQLException
Example to create a SQL statement
ResultSet rs=s.executeQuery("select * from user");
31. STEP 6- Process the results.
❏ Process the Result In this step we receives the result of execute statement. In
this case we will fetch the student records from the recordset object and show
on the command prompt.
Here is the code:
// 1 2
//rollno name
Example to create a SQL statement
while(rs.next())
{
System.out.println(rs.getInt(1)+" "+rs.getString(2));
//System.out.println(rs.getInt(“Rollno”)+" "+rs.getString(2));
}
Rollno Name
Student
32. STEP 7- Closing the connection
❏ This is final step which includes closing all the connection that we opened in
our previous steps.
❏ After executing SQL statement you need to close the connection and release
the session.
❏ The close() method of Connection interface is used to close the connection.
Syntax of the method is given below.
public void close() throws SQLException
Example to create a SQL statement
con.close();
33. Example
import java.sql.*;
class Test {
public static void main(String[] args) {
try {
//Loading driver
Class.forName("oracle.jdbc.driver.OracleDriver");
//creating connection
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE",
"usrname", "pssword");
Statement s = con.createStatement(); //creating statement
ResultSet rs = s.executeQuery("select * from Student"); //executing statement
while (rs.next()) {
System.out.println(rs.getInt(1) + " " + rs.getString(2));
}
con.close(); //closing connection
} catch (Exception e) {
e.printStacktrace();
} } }
34. ResultSet Interface
- The object of ResultSet maintains a cursor pointing to a row of a table.
- Initially, cursor points to before the first row.
- By default, ResultSet object can be moved forward only and it is not updatable.
- But we can make this object to move forward and backward direction by passing either
TYPE_SCROLL_INSENSITIVE or TYPE_SCROLL_SENSITIVE in createStatement(int,int)
method as well as we can make this object as updatable by:
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
Type Description
ResultSet.TYPE_FORWARD_ONLY The cursor can only move forward in the result set.
ResultSet.TYPE_SCROLL_INSENSITIVE The cursor can scroll forward and backward, and the result set is not sensitive to
changes made by others to the database that occur after the result set was created.
ResultSet.TYPE_SCROLL_SENSITIVE. The cursor can scroll forward and backward, and the result set is sensitive to
changes made by others to the database that occur after the result set was created.
35. ResultSet Interface - Methods
Type Description
1) public boolean next(): is used to move the cursor to the one row next from the current position.
2) public boolean previous(): is used to move the cursor to the one row previous from the current position.
3) public boolean first():
is used to move the cursor to the first row in result set object.
4) public boolean last():
is used to move the cursor to the last row in result set object.
5) public boolean absolute(int row):
is used to move the cursor to the specified row number in the ResultSet object.
6) public boolean relative(int row):
is used to move the cursor to the relative row number in the ResultSet object, it
may be positive or negative.
7) public int getInt(int columnIndex):
is used to return the data of specified column index of the current row as int.
8) public int getInt(String columnName):
is used to return the data of specified column name of the current row as int.
9) public String getString(int columnIndex): is used to return the data of specified column index of the current row as String.
10) public String getString(String
columnName):
is used to return the data of specified column name of the current row as String.
36. Example
import java.sql.*;
class FetchRecord{
public static void main(String args[])throws Exception{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery("select * from employee");
//getting the record of 4th row
rs.absolute(4);
System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3));
con.close();
}}
the simple example of ResultSet interface to retrieve the data of 4th row.
38. Handling SQL Exceptions
❏ The java.sql package provides the SQLException class , which is derived from the
java.lang.Exception class.
❏ The SQLException is thrown by various methods in the JDBC API and enables
you to determine the reason of the errors that occur while connecting a Java
application to a database.
❏ You can catch the SQLException in a Java application using the try and catch
exception handling block.
❏ The methods in the SQLException class are :
- int getErrorCode () : Returns the error code associated with the error occurred.
- String getSQLState() : X/Open error code.
- SQLException getNextException () : Returns the next exceptions in the chain of
exceptions.
42. Statement interface
❏ Statement interface resides in java.sql package and it is used to execute a static
SQL statement and returning the result of the executed query.
❏ Statement interface has two sub-interfaces CallableStatement and
PreparedStatement.
❏ get a Statement object by calling the Connection.createStatement() method on
the Connection object.
43. Statement interface Methods
The Statement interface provides various methods
1. boolean execute(String sql) : Executes the given SQL statement (it can be any kind
of SQL query), which may return multiple results.
Returns a boolean which is true if the first result is a ResultSet object; false if it is an
update count or there are no results.
2. ResultSet executeQuery(String sql): Executes the given SQL statement, which
returns a single ResultSet object. If you want to execute a Select SQL query which returns
results you should use this method.
3. int executeUpdate(String sql): Executes the given SQL statement, which may be an
INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as
an SQL DDL statement.Returns an int denoting either the row count for the rows that are
inserted, deleted, updated or returns 0 if nothing is returned.
Note:This method cannot be called on a PreparedStatement or CallableStatement.
4. int[] executeBatch(): Submits a batch of commands to the database for execution
and if all commands execute successfully, returns an array of update counts.
44. PreparedStatement interface
❏ The PreparedStatement objects accepts the runtime parameters.
❏ The PreparedStatement interface is derived from the Statement interface and is
available in the java.sql package.
❏ The PreparedStatement objects are compiled and prepared only once by JDBC.
The future invocation of the PreparedStatement object does not recompile the
SQL statements.
❏ This helps in reducing the load on the database server and thus improving the
performance of the application .
45. PreparedStatement interface
❏ The PreparedStatement interface inherits the following methods to execute SQL
statement s from the Statement interface:
- ResultSet executeQuery () : Executes a SELECT statement and returns the result
in a ResultSet object.
- int executeUpdate(): Executes an SQL statement, INSERT , UPDATE , or
DELETE and returns the count of the rows affected.
- boolean execute () : Executes an SQL statement and returns a boolean value.
46. PreparedStatement interface
stat = con.prepareStatement(“SELECT * FROM authors WHERE au_id = ? ”) ;
The SQL statement can contain ‘ ? ‘ symbol as placeholder that can be replaced
by input parameters at runtime.
Before executing the SQL statements specified in the PreparedStatement object ,
you must set the value of each ‘ ? ‘ parameter.
This is done by calling an appropriate setXXX () method , where XXX is the data
type of the parameter.
stat.setString (1, “123”);
ResultSet rs = stat.executeQuery ();
47. PreparedStatement interface Methods
The PreparedStatement interface provides various methods to set the value of the
placeholders for the specific data types.
1. void setByte (int index , byte val) : Sets the java byte type value for the
parameter corresponding to index passed as a parameter.
2. void setBytes (int index , byte[] val) : Sets the Java byte type array for the
parameter corresponding to index passed as a parameter.
3. void setBoolean (int index , boolean val) : Sets the Java boolean type value for
the parameter corresponding to index passed as a parameter.
4. void setDouble (int index, double val) : Sets the Java double type value value
for the parameter corresponding to the index passed as a parameter.
48. PreparedStatement interface Methods
5. void setInt (int index , int val) : Sets the Java int type value for the parameter
corresponding to index passed as a parameter.
6. void setLong(int index , long val) : Sets the Java long type value for the
parameter corresponding to index passed as a parameter.
7. void setFloat (int index , float val) : Sets the Java float type value for the
parameter corresponding to index passed as a parameter.
8. void setShort (int index , short val) : Sets the Java short type value for the
parameter corresponding to index passed as a parameter.
9. void setString(int index , String val) : Sets the Java String type value for the
parameter corresponding to index passed as a parameter.
51. Updating & Deleting Row
String str = “ UPDATE authors SET state = ? WHERE city = ? “ ;
PreparedStatement ps = con.prepareStatement(str);
ps.setString (1, “MH”);
ps.setString (2, “Pune”);
int rt = ps.executeUpdate() ;
String str = “ DELETE FROM authors WHERE au_fname = ? “ ;
PreparedStatement ps = con.prepareStatement(str);
ps.setString (1, “PPPP”);
int rt = ps.executeUpdate() ;
52. Creating Stored Procedures
❏ You can use the executeUpdate () to execute the CREATE PROCEDURE SQL statement.
❏ Stored procedures can be of two types , parameterized and non- parameterized. Non –
parameterized stored procedure in a JDBC application:
❏ When you use the stored procedures to perform database operations, it reduces network
traffic because instead of sending multiple SQL statements to a database , a single stored
procedure is executed.
String str = “ CREATE PROCEDURE authors_info” + “AS” + “SELECT au_id ,
au_lname , au_fname” + ”FROM authors” + “WHERE city = ‘Pune’ ” + ”ORDER
BY au_fname” ;
Statement stmt = con.createStatement () ;
int rt = stmt.executeUpdate (str);
The Connection object con is used to send the CREATE PROCEDURE SQL statement to a
database. When you execute the code , the authors_info stored procedure is created and
stored in the database.
53. Creating Stored Procedures
You can use the following code snippet to create a parameterized stored procedure.
String str = “ CREATE PROCEDURE authors_info_prmtz @auth_id varchar(15) ,
@auth_fname varchar(20) output , @auth_lname varchar(20) output , @auth_city
varchar(20) output , @auth_state varchar(20) output ” + “AS”
+ “SELECT @auth_fname = au_fname , @auth_lname = au_lname , @auth_city = city
, @auth_state = state ” + “ FROM authors ” + “ WHERE au_id = @auth_id ” ;
Statement stmt = con.createStatement () ;
int rt = stmt.executeUpdate (str);
54. Creating Stored Procedures
- In the preceding code snippet , the authors_info_prmtz stored procedure is
created that accepts author id as parameter and retrieve the corresponding author
information form the database.
- The retrieved information is stored in the OUT parameter. The SQL Server 2000
uses output keyword to represent OUT parameters.
- A stored procedure can accepts one or multiple parameters.
- A parameter of a stored procedure can take any of these forms :
1. IN : Refers to the argument that you pass to a stored procedure.
2. OUT : Refers to the return value of a stored procedure.
3. INOUT : Combines the functionality of the IN and OUT parameters. The
INOUT parameter enables you to pass an argument to a stored procedure.
The same parameter can also be used to store a return value of a stored
procedure
55. Calling a Stored Procedure without Parameters
- The Connection interface provides the prepareCall() method that is used to create the
CallableStatement object .
- This object is used to a call a stored procedure of a database .
- The prepareCall () is an overloaded method that has the following 3 forms:
1. CallableStatement prepareCall (String str) : Creates a CallableStatement object to call a stored
procedure. The prepareCall () accepts a string as a parameter that contains an SQL statement to call
a stored procedure. You can also specify the placeholders to accept parameters in the SQL
statement.
2. CallableStatement prepareCall(String str , int resSetType , int resSetConc): Creates a
CallableStatement object that returns ResultSet object that has the specified result set type and
concurrency mode. The method accepts following 3 parameter :
String object :Contains the SQL statement to call a stored procedure. The SQL statement can
contains one or more parameters.
ResultSet types : Specifies any of the 3 result set types , TYPE_FORWARD_ONLY ,
TYPE_SCROLL_INSENSITIVE or TYPE_SCROLL_SENSITIVE.
ResultSet concurrency modes :Specifies either of these concurrency modes ,
CONCUR_READ_ONLY or CONCUR_UPDATABLE , for a result set
56. Calling a Stored Procedure without Parameters
3. CallableStatement prepareCall (String str , int resSetType , int resSetConcur , int
resSetHoldability) : Creates a CallableStatement object that returns a ResultSet object . This
ResultSet object has the specified result type, concurrency mode, and constant to set the result set
state.
The syntax to call a stored procedure without parameter is : { call <procedure_name> } ;
Eg:
String str = “ {call authors_info}” ;
CallableStatement cs = con.prepareCall (str) ;
ResultSet rs = cs.executeQuery() ;
while(rs.next()) {
System.out.println(“Author ID :” + rs.getString(1) + “t”);
System.out.println(“Author First Name :” + rs.getString(2) + “t”);
System.out.println(“Author Last Name :” + rs.getString(3) + “t”);
}
57. Calling a Stored Procedure with Parameters
- The SQL escape syntax is used to call a stored procedure with parameters.
- There are two forms of the SQL escape syntax, one that contains result parameter and one
that does not.
- If the SQL escape syntax contains a result parameter, the result parameter is used to return
a value from a stored procedure.
- The result parameter is an OUT parameter. Other parameters of the SQL escape syntax can
contain IN , OUT , or INOUT parameters.
- The syntax to call a stored procedure with parameter is :
{ call <procedure_name> (?)} ;
- You need to set the value of the IN parameters before the CallableStatement object
executed , otherwise the SQLException is thrown while processing the stored procedure.
<CallableStatement_object>.setInt(<value>)
58. Calling a Stored Procedure with Parameters
- If the stored procedure contains OUT and INOUT parameters, these parameters should be
registered with corresponding JDBC types before a call to a stored procedures is processed.
- The JDBC types determine the Java data types that are used in the get methods while
retrieving the values of the OUT and INOUT parameters.
cs.registerOutParameter (1 . Java.sql.Types.STRING) ;
Accepts the position of the placeholder and a constant in the java.sql.Types class as
parameters.
cs.registerOutParameter (1, java.sql.Types.DECIMAL , 3) ;
What for 3rd Parameter used for ?
59. Calling a Stored Procedure with Parameters
import java.sql.*;
public class CallProc { public static void main(String arg []) {
String id , fname , lname , address , city ;
try { String str = “ { call authors_info ( ? , ? , ? , ? , ? ) } ” ;
Class.forname (“sun.jdbc.odbc.JdbcOdbcDriver”);
Connection con = DriverManager.getConnection(“jdbc:odbc:DSN”) ;
CallableStatement cs = con.prepareCall (str) ;
cs.setString (1 , “123-456” ) ; // pass IN parameter
//Register OUT paramter
cs.registerOutParameter(2 , Types.VARCHAR);
cs.registerOutParameter(3 , Types.VARCHAR);
cs.registerOutParameter(4 , Types.VARCHAR);
cs.registerOutParameter(5 , Types.VARCHAR);
// process the Stored procedure
cs.execute () ;
fname = cs.getString(2) ;
lname = cs.getString(3) ;
address = cs.getString(4) ;
city = cs.getString(5) ;
-----
---- }}
60. ResultSetMetaData
- The ResultSetMetaData interface contains various methods that enable you to retrieve
information about the data in a result set , such as number of columns , names of columns and
data types of the columns.
- The ResultSet interface provides the getMetaData () method to create an object of the
ResultSetMetaData interface .
ResultSetMetaData rm = rs.getMetaData() ;
The following lists the commonly used methods of the ResultSetMetaData interface :
- int getColumnCount () : Returns an integer indicating the total number of columns in a ResultSet
object .
- String getColumnLabel (int col_index) : Retrieves the title of the table column corresponding to
the index passed as a parameter to this method.
- String getColumnName (int col_index) : Retrieves the name of the table column corresponding to
the index passed as a parameter to this method.
- int getColumnType (int col_index) : Retrieves the SQL data type of the table column
corresponding to the index passed as a parameter.
61. ResultMetaData
- String getTableName(int col_index) : Retrieves the name of the database table that contains the
column corresponding to the index passed as a parameter.
- boolean isAutoIncrement (int col_index) : Returns a boolean value that indicates whether the
table column corresponding to the index passed as a parameter increments automatically.
- boolean isCaseSensitive (int col_index) : Returns a boolean value that indicates whether the
table column corresponding to the index passed as a parameter is case sensitive.
- boolean isReadOnly (int col_index) : Returns a boolean value that indicates whether the column
in a ResultSet corresponding to the index passed as a parameter is read only.
- boolean isWritable (int col_index) : Returns a boolean value that indicates whether ResultSet
column corresponding to the index passed as a parameter is updatable.