)
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
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.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();
}
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) );
}
}
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 ,