0% found this document useful (0 votes)
29 views7 pages

FT 2 Answer

ft2 annnnswers

Uploaded by

paulson8739
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views7 pages

FT 2 Answer

ft2 annnnswers

Uploaded by

paulson8739
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

FT 2-WEB TECHNOLOGY

1.
 Persistence: Cookies can be persistent or session-based, which
will be dependent on the time duration of data to last.
 Tracking: Cookies are used as trackers to collect user’s
behaviour which will be helpful for marketing strategies, improving
content, etc.
 Authentication: Cookies are essential for maintaining the user’s
session and authentication to stay logged in.

2.

BACK button/Reload Harmless Data will be re-submitted (the browser should a


are about to be re-submitted)

Bookmarked Can be bookmarked Cannot be bookmarked

Cached Can be cached Not cached

Restrictions on data Only ASCII characters No restrictions. Binary data is also allowed
type allowed

3. JDBC is an API(Application programming interface) used in Java


programming to interact with databases.
The classes and interfaces of JDBC allow the
application to send requests made by users to the specified
database.
4. Application Programming Interface that is a collection of
communication protocols and subroutines used by various programs
to communicate between them. A programmer can make use of
various API tools to make their program easier and simpler. Also, an
API facilitates programmers with an efficient way to develop their
software programs.

5. 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. There are four types of JDBC drivers:

o JDBC-ODBC Bridge Driver,


o Native Driver,
o Network Protocol Driver, and
o Thin Driver

10marks
6.
To create a book database with a `members` table and write a JDBC (Java Database
Connectivity) program to query and print all entries in the `members` table, you need
to follow these steps:
1. **Set Up Your Database**:
First, you'll need to set up a database management system (DBMS) such as MySQL,
PostgreSQL, SQLite, etc., and create a database with a `members` table. Here's an
example SQL script to create a simple `members` table in MySQL:
```sql
CREATE DATABASE book_database;
USE book_database;
CREATE TABLE members (
member_id INT PRIMARY KEY AUTO_INCREMENT,
member_name VARCHAR(255) NOT NULL
);
```
This script creates a database called `book_database` and a table called `members`
with two columns: `member_id` and `member_name`.
2. **Install a JDBC Driver**:
You'll need the JDBC driver for your specific database system. Download and add the
JDBC driver JAR file to your Java project's classpath.
3. **Write the JDBC Program**:
Here's a Java program that connects to the database, queries the `members` table, and
prints all entries:
```java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class MemberDatabase {
public static void main(String[] args) {
String jdbcUrl = "jdbc:mysql://localhost:3306/book_database"; // Replace with your
database URL
String username = "your_username"; // Replace with your database username
String password = "your_password"; // Replace with your database password
try {
// 1. Load the JDBC driver
Class.forName("com.mysql.cj.jdbc.Driver");
// 2. Establish a database connection
Connection connection = DriverManager.getConnection(jdbcUrl, username,
password);
// 3. Create a SQL statement
Statement statement = connection.createStatement();
// 4. Execute a SQL query
String sqlQuery = "SELECT * FROM members";
ResultSet resultSet = statement.executeQuery(sqlQuery);
// 5. Process the result set
while (resultSet.next()) {
int memberId = resultSet.getInt("member_id");
String memberName = resultSet.getString("member_name");
System.out.println("Member ID: " + memberId + ", Name: " + memberName);
}
// 6. Close the resources
resultSet.close();
statement.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
```
Make sure to replace `"your_username"` and `"your_password"` with your
database credentials, and `"jdbc:mysql://localhost:3306/book_database"` with your
actual database URL.
4. **Compile and Run the Program**:
Compile the Java program and run it. It should connect to the database, retrieve
data from the `members` table, and print the results to the console.
Ensure that you have the necessary database and JDBC driver configured correctly
to run this program successfully.

7. Java Database Connectivity. It’s an advancement for ODBC


( Open Database Connectivity ). JDBC is a standard API
specification developed in order to move data from the front end to
the back end. This API consists of classes and interfaces written in
Java. It basically acts as an interface (not the one we use in Java)
or channel between your Java program and databases i.e it
establishes a link between the two so that a programmer can send
data from Java code and store it in the database for future use.

Steps to Connect Java Application with


Database
Below are the steps that explains how to connect to Database
in Java:
Step 1 – Import the Packages
Step 2 – Load the drivers using the forName() method
Step 3 – Register the drivers using DriverManager
Step 4 – Establish a connection using the Connection class object
Step 5 – Create a statement
Step 6 – Execute the query
Step 7 – Close the connections
Java Database Connectivity

 Import the packages − Requires that you include the packages containing the
JDBC classes needed for database programming. Most often, using import java.sql.* will
suffice.
 Open a connection − Requires using the DriverManager.getConnection() method
to create a Connection object, which represents a physical connection with the database.
 Execute a query − Requires using an object of type Statement for building and
submitting an SQL statement to the database.
 Extract data from result set − Requires that you use the
appropriate ResultSet.getXXX() method to retrieve the data from the result set.
 Clean up the environment − Requires explicitly closing all database resources
versus relying on the JVM's garbage collection.
 import java.sql.*;

 public class SelectExample {
 static final String DB_URL = "jdbc:mysql://localhost/TUTORIALSPOINT";
 static final String USER = "guest";
 static final String PASS = "guest123";
 static final String QUERY = "SELECT id, first, last, age FROM Employees";

 public static void main(String[] args) {
 // Open a connection
 try(Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
 Statement stmt = conn.createStatement();
 ResultSet rs = stmt.executeQuery(QUERY);) {
 // Extract data from result set
 while (rs.next()) {
 // Retrieve by column name
 System.out.print("ID: " + rs.getInt("id"));
 System.out.print(", Age: " + rs.getInt("age"));
 System.out.print(", First: " + rs.getString("first"));
 System.out.println(", Last: " + rs.getString("last"));
 }
 } catch (SQLException e) {
 e.printStackTrace();
 }
 }
 }

Output:

 C:\>java SelectExample
 Connecting to database...
 Creating statement...
 ID: 100, Age: 18, First: Zara, Last: Ali
 ID: 101, Age: 25, First: Mahnaz, Last: Fatma
 ID: 102, Age: 30, First: Zaid, Last: Khan
 ID: 103, Age: 28, First: Sumit, Last: Mittal

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy