FSD_UNIT5
FSD_UNIT5
FSD_UNIT5
Ans:
In the context of relational databases like SQL, there are three types of SQL commands:
Examples:
- **CREATE TABLE:** This command is used to create a new table in the database. For example:
```sql
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Salary DECIMAL(10, 2)
);
```
- **ALTER TABLE:** This command is used to modify an existing table structure. For example, adding a new column:
```sql
ALTER TABLE Employees
ADD Email VARCHAR(100);
```
- **DROP TABLE:** This command is used to delete an existing table and all its data. For example:
```sql
DROP TABLE Employees;
```
Examples:
- **INSERT INTO:** This command is used to add new records into a table. For example:
```sql
INSERT INTO Employees (EmployeeID, FirstName, LastName, Salary)
VALUES (1, 'John', 'Doe', 50000);
```
- **UPDATE:** This command is used to modify existing records in a table. For example:
```sql
UPDATE Employees
SET Salary = 55000
WHERE EmployeeID = 1;
```
- **DELETE:** This command is used to remove records from a table. For example:
```sql
DELETE FROM Employees
WHERE EmployeeID = 1;
```
Examples:
- **GRANT:** This command is used to give specific privileges to a user or role. For example, granting SELECT
permission on a table:
```sql
GRANT SELECT ON Employees TO User1;
```
- **REVOKE:** This command is used to take away previously granted privileges. For example, revoking the SELECT
permission:
```sql
REVOKE SELECT ON Employees FROM User1;
```
2) write a program to insert a record using spring jdbc
Ans:
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
// Create a JdbcTemplate
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
// Clean up and close the DataSource (not needed for long-running applications)
dataSource.getConnection().close();
}
}
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
// Create a JdbcTemplate
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
// Clean up and close the DataSource (not needed for long-running applications)
dataSource.getConnection().close();
}
}
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
// Create a JdbcTemplate
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
// Clean up and close the DataSource (not needed for long-running applications)
dataSource.getConnection().close();
}
}
5) Write a simplified program to perform any DML operation using Spring JDBC.
Ans:
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
// Create a JdbcTemplate
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
// Clean up and close the DataSource (not needed for long-running applications)
dataSource.getConnection().close();
}
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import java.util.List;
import java.util.Map;
// Create a JdbcTemplate
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
// Clean up and close the DataSource (not needed for long-running applications)
dataSource.getConnection().close();
}