PART – A
1. What is DBMS.?
DBMS (DataBase Management System) is a software or program used to create or manage any database.
2. What is a database?
A Database is an organized collection of data.
3. What does record and field represent?
* Rows in a table represent Records.
* Columns in a table represent Fields.
4. What is SQL ?
SQL is a standard language for managing any kinds of database
Example Operations: Create a database or table .
5. Mention the major two types of SQL Commands.
* Data Definition Language:
CREATE, ALTER, DROP – a table or database.
* Data Manipulation Language:
SELECT, INSERT INTO, DELETE, UPDATE
6. What is JDBC?
JDBC (Java DataBase Connectivity) is an API used to connect Java applications to a database and then query or update it, using the SQL.
7. Draw the architecture for JDBC connection to database.
8. List the four types of JDBC drivers.
Type 1: JDBC / ODBC Bridge.
Type 2: Native – API Driver.
Type 3: Network Protocol Driver – Middle Ware Driver.
Type 4: Native Protocol Driver – Pure JAVA Driver.
9. Difference between two tier and three tier database architecture.
Two Tier Architecture
|
Three Tier Architecture
|
* In a two-tier model, a Java application/applet communicates directly with the database, via the JDBC driver.
|
* In a three-tier model, a Java application communicates with a middle tier component that functions as an application server.
|
** DIAGRAM IS GIVEN BELOW **
|
** DIAGRAM IS GIVEN BELOW **
|
· Programmers can write applications in the Java programming language to access any database, using SQL statements.
· Database vendors can supply the low-level drivers. Thus, they can optimize their drivers for their specific products.
11. Write the simple SQL statement for creating a table.
CREATE TABLE it_b_section
(
name VARCHAR(60),
reg_no VARCHAR(13),
(
name VARCHAR(60),
reg_no VARCHAR(13),
cgpa INT(6)
)
· createStatement()- creates a Statement object that can be used to execute SQL queries and updates without parameters.
· executeQuery()- executes the SQL statement given in the string and returns a ResultSet object to view the query result
22. Write a Program to display the cgpa, name, reg from the database.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:sast
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM stu1");
while(rs.next()==true)
{
System.out.print(rs.getString("cgpa"));
System.out.print("\t"+rs.getString(2));
System.out.println("\t"+rs.getString(3));
}
st.close();
con.close();
23. Write a SQL statement to join the two tables. Both contain one same attributes (reg_no).
createStatement
Points to remember :
* Inside brackets() , set length of the field.
* it_b_section is the TABLE NAME.
12. Write all the data types of SQL.
13. Write a simple SQL statement to display all the data in a table.
SELECT * FROM it_b_section
14. Write a simple SQL statement to display the details of students whose JAVA internal is above 40.
SELECT * FROM it_b_section WHERE java_marks > 40
15. Write a simple SQL statement to insert values into a table.
INSERT INTO it VALUES (‘Aslam Jainul’, ‘115015048’ , ‘ ’)
16. “Your facebook password is weak. Now you are going to change your password”. Write a SQL statement for the above problem.
Here login is the table name and mail and password are attributes.
____________________________________________________
For the above questions (13,14,15,16) , the question is only to write a SQL statement.
EASY TO REMEMBER
INSERT INTO
|
VALUES
|
UPDATE
|
SET
|
_______________________________________________________
17. Write a Statement for loading and registering JDBC ODBC driver.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
18. Write a Statement for creating connection to database.
Connection con=DriverManager.getConnection("jdbc:odbc:sastra","","");
Parameters Involved:
1.Database Url
2.DB username
3.DB Password.
19. Explain about database URL for creating connection to database
The general syntax is
jdbc : subprotocol : other stuff
Example : jdbc:odbc:sastra
Example : jdbc:odbc:sastra
where
subprotocol - specific driver for connecting to the database.
stuff - depends on the subprotocol used.
20. Write a program for read a properties file and opening the database connection.
Properties props = new Properties();
FileInputStream in = new FileInputStream("database.properties");
props.load(in);
in.close();
String drivers = props.getProperty("jdbc.drivers");
if (drivers != null)
System.setProperty("jdbc.drivers", drivers);
String url = props.getProperty("jdbc.url");
String username = props.getProperty("jdbc.username");
String password = props.getProperty("jdbc.password");
return DriverManager.getConnection(url, username, password);
21. Write any three methods involved in connection to a database.
·getConnection() - establishes a connection to the given database and returns a Connection object.
· createStatement()- creates a Statement object that can be used to execute SQL queries and updates without parameters.
· executeQuery()- executes the SQL statement given in the string and returns a ResultSet object to view the query result
22. Write a Program to display the cgpa, name, reg from the database.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:sast
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM stu1");
while(rs.next()==true)
{
System.out.print(rs.getString("cgpa"));
System.out.print("\t"+rs.getString(2));
System.out.println("\t"+rs.getString(3));
}
st.close();
con.close();
23. Write a SQL statement to join the two tables. Both contain one same attributes (reg_no).
SELECT * FROM it_b_section , it_department
WHERE reg_no = “115015048”
24. Write a SQL statement to display the student details according to cgpa from highest to lowest.
SELECT * FROM it_b_section
ORDER BY cgpa DESC
25. Describe the mapping type of JDBC - JAVA.
26. Write a Program to explain Scrollable Result Set.
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String query = “select students from class where type=‘not sleeping’ “;
ResultSet rs = stmt.executeQuery( query );
rs.previous();
rs.relative(-5); / / go 5 records back
rs.relative(7); / / go 7 records forward
rs.absolute(100); / / go to 100th record
27. Write a Program to explain Updateable Resultset.
createStatement
(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE);
while ( rs.next() )
{
int grade = rs.getInt(“grade”);
rs.updateInt(“grade”, grade+10);
rs.updateRow();
}
Connection con = …. ; DatabaseMetaData dbmd = con.getMetaData();
String catalog = null;
String schema = null;
String table = “sys%”;
String[ ] types = null;
ResultSet rs = dbmd.getTables(catalog , schema , table , types );
29. Write a Program to illustrate MetaData from RS.
public static void printRS(ResultSet rs) throws SQLException
{
ResultSetMetaData md = rs.getMetaData();
// get number of columns int nCols = md.getColumnCount();
// print column names
for(int i=1; i < nCols; ++i)
System.out.print( md.getColumnName( i)+",");
/ / output resultset
while ( rs.next() )
{
while ( rs.next() )
{
int grade = rs.getInt(“grade”);
rs.updateInt(“grade”, grade+10);
rs.updateRow();
}
28. Write a Program to illustrate MetaData from DB.
Connection con = …. ; DatabaseMetaData dbmd = con.getMetaData();
String catalog = null;
String schema = null;
String table = “sys%”;
String[ ] types = null;
ResultSet rs = dbmd.getTables(catalog , schema , table , types );
29. Write a Program to illustrate MetaData from RS.
public static void printRS(ResultSet rs) throws SQLException
{
ResultSetMetaData md = rs.getMetaData();
// get number of columns int nCols = md.getColumnCount();
// print column names
for(int i=1; i < nCols; ++i)
System.out.print( md.getColumnName( i)+",");
/ / output resultset
while ( rs.next() )
{
for(int i=1; i < nCols; ++i)
System.out.print( rs.getString( i)+",");
System.out.println( rs.getString(nCols) );
}
}
________________________________________________________________________________
System.out.print( rs.getString( i)+",");
System.out.println( rs.getString(nCols) );
}
}
PART – B
1. Explain the four types of JDBC Drivers.
2. Explain the JDBC installation Process.
3. Write a program for Scrollable and Updateable ResultSet.
4. Write a simple program for JDBC connection. Explain It.
5. Write a program to create a database on ORACLE database.
6. Write a program to execute any 5 Queries.
7. Explain Structured Query Language. Explain with SQL Statements.
________________________________________________________________________________
Tags : java, java important 2 marks, jdbc, jdbc 2 marks, sastra java, sastra java question paper, sastra university, java jdbc , jdbc driver , anna university java syllabus , sastra university java syllabus , sastra university java question papers , anna university java question papers ,
Content-wise the page is good .
ReplyDeleteBut it would be nice ,if it was more readable .
The background and foreground color is just annoying, making it irritating .