Ans: Database is a collection of interrelated data. Database management system is a software which can be used to manage the data by storing it on to the data base and by retrieving it from the data base. And DBMS is a collection of interrelated data and some set of programs to access the data.
There are 3 types of Database Management Systems:
Ans:
Ans: The main components of JDBC consists of the following phases:
DriverManager: Manages a list of database drivers. Matches connection requests from the java application with the proper database driver using communication subprotocol. The first driver that recognizes a certain subprotocol under JDBC will be used to establish a database Connection.Ans:
Ans:
Ans:
public Statement createStatement()
Eg: Statement st = con.createStatement();
Ans: st.executeQuery(…)
st.executeUpdate(…)
st.execute(…)
To execute the sql queries we will use the following methods from Statement object.
Ans:
import java.sql.*;
import java.io.*;
public class CreateTableEx
{
public static void main(String[] args)throws Exception
{
//create buffered reader object
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//load and register the driver
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
//establish connection
Connection con = DriverManager.getConnection(“jdbc:odbc:nag”,”system”,”durga”);
//create statement object
Statement st = con.createStatement();
//take table name as dynamic input
System.out.println(“Enter table name”);
String tname = br.readLine();
//execute sql query
St.executeUpdate(“create table”+tname+”(eno number,ename varchar2(10),esal number,eaddr varchar2(10))”);
System.out.println(“table created successfully”);
//closing the connection
con.close();
}
}
//import section
Ans:
import java.io.*;
public class InsertTableEx
{
public static void main(String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Class.forName(“oracle.jdbc.driver.OracleDriver”);
Connection con = DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:xe”,”system”,”durga”);
Statement st = con.createStatement();
while(true)
{
System.out.println(“Enter emp number”);
Int eno = Integer.parseInt(br.readLine());
System.out.println(“Enter emp name”);
String ename = br.readLine();
System.out.println(“Enter emp sal”);
Float esal = Float.parseFloat(br.readLine());
System.out.println(“Enter emp address”);
String eaddr = br.readLine();
st.executeUpdate(“insert into emp1 values(“+eno+”,’”+ename+”’,”+esal+”,’”+eaddr+”’)”);
System.out.println(“read successfully inserted”);
System.out.println(“one more record[y/n]);
String option = br.readLine();
If(option.equals(“n”))
break;
}
}
}
import java.sql.*;
Ans:
import java.sql.*;
public class UpdateTableEx
{
public static void main(String[] args)throws Exception
{
//load n register the driver in alternative way to Class.forName
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection con = DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:xee”,”system”,”durga”);
Statement st = con.createStatement();
int updateCount = st.executeUpdate(“update emp1 set esal = esal+500 where esal<9000”);
System.out.println(“records updated……..”+updateCount);
con.close();
}
}
Ans: INNER JOIN: Returns all rows when there is at least one match in BOTH tables
LEFT JOIN: Return all rows from the left table, and the matched rows from the right table
RIGHT JOIN: Return all rows from the right table, and the matched rows from the left table
FULL JOIN: Return all rows when there is a match in ONE of the tables
Ans: There are 3 types of Statements, as given below:
Statement:
It can be used for general-purpose access to the database. It is useful when you are using static SQL statements at runtime.
PreparedStatement:
It can be used when you plan to use the same SQL statement many times. The PreparedStatement interface accepts input parameters at runtime.
CallableStatement:
CallableStatement can be used when you want to access database stored procedures.