Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery("SELECT * FROM table")); int columnCount = resultSet.getMetaData().getColumnCount();
Select the correct statement, which applies? A. Table header can be accessed using 0th Index. B. Table header can be accessed using 1st Index C. MetaData object cannot return number of columns in query. D. A and C E. B and C
An object that can be used to get information about the types and properties of the columns in a ResultSet object. The following code fragment creates the ResultSet object rs, creates the ResultSetMetaData object rsmd, and uses rsmd to find out how many columns rs has and whether the first column in rs can be used in a WHERE clause.
ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2"); ResultSetMetaData rsmd = rs.getMetaData(); int numberOfColumns = rsmd.getColumnCount(); boolean b = rsmd.isSearchable(1);
Question : You have been given below code, once you execute it what will be the expected result?
Correct Answer : Get Lastest Questions and Answer : Explanation: This code will throw run time error. Because if you want to use ResultSet, you should use next() method on it. while (resultSet.next()) should be used.
Question : Select the correct statement with regards to JDBC Statement interface
1. The Statement interface and its derived interfaces implement the AutoCloseable interface, hence Statement objects can be used with the try with- resources statement.
2. You can use PreparedStatement is used to execute stored procedures
The object used for executing a static SQL statement and returning the results it produces. By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All execution methods in the Statement interface implicitly close a current ResultSet object of the statement if an open one exists. java.sql.PreparedStatement
An object that represents a precompiled SQL statement. A SQL statement is precompiled and stored in a PreparedStatement object. This object can then be used to efficiently execute this statement multiple times. Note: The setter methods (setShort, setString, and so on) for setting IN parameter values must specify types that are compatible with the defined SQL type of the input parameter. For instance, if the IN parameter has SQL type INTEGER, then the method setInt should be used. If arbitrary parameter type conversions are required, the method setObject should be used with a target SQL type. In the following example of setting a parameter, con represents an active connection: PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES SET SALARY = ? WHERE ID = ?"); pstmt.setBigDecimal(1, 153833.00) pstmt.setInt(2, 110592)
java.sql.CallableStatement
The interface used to execute SQL stored procedures. The JDBC API provides a stored procedure SQL escape syntax that allows stored procedures to be called in a standard way for all RDBMSs. This escape syntax has one form that includes a result parameter and one that does not. If used, the result parameter must be registered as an OUT parameter. The other parameters can be used for input, output or both. Parameters are referred to sequentially, by number, with the first parameter being 1. {?= call [(,, ...)]} {call [(,, ...)]}