Chapter_5.gpp
Chapter_5.gpp
A) ParameterizedStatement B) PreparedStatement
C) ParameterizedStatement and CallableStatement
D) All kinds of Statements
A) By invoking the method get(String type) on the ResultSet, where type is the
database type
B) By invoking the method get(Type type) on the ResultSet, where Type is an object
which represents a databasetype
C) By invoking the method getValue(), and cast the result to the desired Java type
A) PreparedStatement B)
ParameterizedStatement C) CallableStatement D)
All of the Above
B) This means that the Resultset is sensitive toscrolling, but insensitive to updates, i.e.
not updateable
D) The meaning depends on the type of data source, and the type and version of the
driver you use with this data source
Q6. What happens if you call the method close() on a ResultSet object?
A) the method close() does not exist for a ResultSet. Only Connections can be
closed.
C) you will get a SQLException, because only Statement objects can close
ResultSets
D) the ResultSet, together with the Statement which created it and the Connection
fromwhich the Statement was retrieved, will be closed and release all database and
JDBC resources
Q7. What happens if you call deleteRow() on a ResultSet object?
A) The row you are positioned on is deleted from the ResultSet, but not from the
database.
B) The row youare positioned on is deleted from the ResultSet and from the
database
D) You will get a compile error: the methoddoes not exist because you can not delete
rows from a ResultSet.
A) DDL statements are treated as normal SQL statements, and are executed by
calling the execute() method on a Statement
C) DDLstatements can not be executed by making use of JDBC, you should use the
native database tools for this
D) Support for DDL statements will be a feature of a future release of JDBC
Q9. Which of the following statements is false as far as different type of statements is
concern inJDBC?
A) Regular Statement B) Prepared
Statement C) Callable Statement D) Interim
Statement
Q10. JDBC facilitates to store the java objects by using which of the methods of Prepared
Statement 1.setObject () 2. setBlob() 3. setClob()
Q12. Which of the following describes the correct sequence of the steps involved in making a
connection with a database. 1. Loading the driver 2. Process the results. 3. Making the
connection with thedatabase. 4. Executing the SQL statements.
Q14. Can we retrieve a whole row of data at once, instead of calling an individual
ResultSet.getXXXmethod for each column ?
Q16. In order to transfer data between a database and an application written in the Java
programminglanguage, the JDBC API provides which of these methods?
A) Methods on the ResultSet class for retrieving SQL SELECT results as Java types.
Q19. Which of the following is used to set the maximum number of rows can contain?
Q20. method of ResultSet is used to move the cursor to the row next from the current
position.
Q21. Which of the following encapsulates an SQL statement which is passed to the database
to beparsed, compiled, planned and executed?
Q22. The interface ResultSet has a method, getMetaData(), that returns a/an
A) getNumberOfColumn() B) getMaxColumn()
C) getColumnCount() D) getColumns()
A) ResultSet B) Statement
C) PreparedStatement D) Connection
D) none of these
C) Type-2 driver isn't written in java, that's why it isn't a portable driver
import java.sql.*;
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:MyDSN","","");
PreparedStatement s=c.prepareStatement( "update student set Name=* where Roll_no=*");
s.setString(1,"XYZ");
s.setString(2,"1");
s.executeUpdate();
s.close();
c.close(); } }
A) a. use s.executeQuery() method B) Use ; in main method
C) Use s.setString(2,1) method D) use ? inPreparedStatement
Q90. Which is the incorrect statement in the following Code?
import java.sql.*;
public class Sample1
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:DSN2","","");
PreparedStatement s=c.createStatement( );
ResultSet rs=s.executeQuery("select* from student");
System.out.println("Name"+""+"Roll no"+" "+"Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" "+rs.getInt(2)+" "+rs.getDouble(3));
}
s.close();
c.close();
}
}
A) ResultSet rs=s.executeQuery(); B)
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); C) PreparedStatement
s=c.createStatement(); D) None of the above
Q91. Consider the following program. What should be the correction done in the program to
get correctoutput?
import java.sql.*;
public class DataBase
{
public static void main(String[] args)
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:abc", "", "");
String s1="insert into student values(1,'abc');
s.executeUpdate(s1);
s.close();
conn.close();
}
catch(IOException e)
{
System.out.println(e);
}
}
}
A) Insert try and catch(FileNotFoundException fe)
B) Use s.executeQuery(s1);
C) Insert try and catch(Exception e)
D) Insert catch(Exception e)
Q92. What will be the output of the following program.
import java.sql.*;
import java.io.*;
{
Try
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
ResultSet rs=ps.executeQuery();
if(rs.next())
Blob b=rs.getBlob(2);
FileOutputStream fout=newFileOutputStream("d:\picture.jpg");
fout.write(barr);
fout.close();
}//end of if
con.close();
catch (Exception e)
{
e.printStackTrace();
}
}
}
A) image will be inserted into the database
B) Image will be retrieved from the database.
C) ; missing
D) } missing
Q93. Which of the following statement is used for connectivity with Oracle database?
A) Connection
con=DriverManager.getConnection("odbc:oracle:thin:@localhost:1512:xe","system","or
acle");
B) Connection
con=DriverManager.getConnection("jdbc:thin:oracle:@localhost:1512:xe","system","or
acle"); C) Connection
con=DriverManager.getConnection("odbc:oracle:thin:@localhost:1521:xe","system","o
racle");
D) Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system",
"oracle");
Q94. Consider the following code. Fill the proper method in the blank space to get the
count of total records updated.
import java.sql.Statement;
Try
Class.forName("oracle.jdbc.driver.OracleDriver");
Statement stmt = con.createStatement(); //The query can be update query or can be select
query
if(status)
ResultSet rs = stmt.getResultSet();
while(rs.next())
System.out.println(rs.getString(1));
rs.close();
}
Else