option
Cuestiones
ayuda
daypo
buscar.php

Certificación Java Parte 9

COMENTARIOS ESTADÍSTICAS RÉCORDS
REALIZAR TEST
Título del Test:
Certificación Java Parte 9

Descripción:
Bases de datos, Excepciones, Try con recursos

Fecha de Creación: 2024/02/16

Categoría: Otros

Número Preguntas: 16

Valoración:(0)
COMPARTE EL TEST
Nuevo ComentarioNuevo Comentario
Comentarios
NO HAY REGISTROS
Temario:

Relaciona cada clase o interfaz con su definición correspondiente: DriverManager. Connection. Statement. PreparedStatement. ResultSet.

¿Cual es la forma correcta de cargar en memoria el driver de la base de datos?. Class.forName(“com.mysql.jdbc.Driver”);. Class(“com.mysql.jdbc.Driver”);. Connection(“com.mysql.jdbc.Driver”);. DriverManager(“com.mysql.jdbc.Driver”);.

¿Cual es el formato correcto de la conexión de una base de datos con JDBC?. jdbc: <subprotocolo> subname. <subprotocolo> : jdbc: subname. subname: <subprotocolo> :jdbc.

Dado el siguiente fragmento de código, escoge la opción correcta: String sql2 = "insert into tabla(col1,col2) values(?,?)"; PreparedStatement st2 = con.prepareStatement(sql2); st2.setInt(1,100); st2.setString(2,"test"); st2.executeUpdate(); st2.setInt(1,101); st2.executeUpdate();. Inserta dos filas (100,test) y (101,NULL). Inserta dos filas (100,test) y (101,test). Inserta una fila (100,test). Se lanza una excepción.

Dado el siguiente fragmento de código, escoge la opción correcta: String qry= "select EMAILID, NAME, DEPARTMENT from EMPLOYEE order by EMAILID"; PreparedStatement stmt = connection.prepareStatement(qry); ResultSet rs = stmt.executeQuery(); while(rs.next()){ System.out.println(rs.getString(0)+"|"+rs.getString(1)+"|"+rs.getString(3)); } connection.close(). Lanza una excepción si hay al menos un registro. Lanza una excepción si no hay registros. Imprime el resultado correctamente. Error de compilación.

Dado el siguiente fragmento de código: String sql3 = "select * from data"; Statement st3 =con.createStatement(); // Línea1 ResultSet rs = st.execute(sql3); // Línea2. Se obtiene el resultado de la consulta correctamente. Error de compilación en línea 1. Error de compilación en línea 2.

Relaciona cada método de ResulSet con su opción correspondiente. next. getInt(int x), getString(int x), getLong(int x) ... getInt(String x), getString(String x), getLong(String x).

Dado el siguiente fragmento de código: try { Class.forName("com.mysql.jdbc.Driver"); // Línea1 } catch (ClassNotFoundException e) { throw new RuntimeException(e); } String cadena= "jdbc:mysql://localhost:3306/prueba"; String user = "admin"; String pwd = "123"; try (Connection con = DriverManager.getConnection(cadena, user, pwd)){ // Línea 2 String sql3 = "select * from employees where department = ? "; PreparedStatement pst3 =con.preparedStatement (sql3); // Línea 3 pst3.setString(1,"Marketing") ResultSet rs = pst3.executeQuery(); // Línea 4 while(rs.next()){ System.out.println(rs.getString(1)); } }. Error de compilación en Línea 1. Error de compilación en Línea 2. Error de compilación en Línea 3. Error de compilación en Línea 4. Compila y se ejecuta correctamente.

¿Cuáles de las siguientes excepciones son Unckecked?. ArithmethicExcepcion. NullPointerExcepcion. IndexOutOfBoundsException. ClassCastException. IOException. SQLException. ArrayIndexOutOfBoundsException. IllegalArgumentException.

Relaciona los tipos de excepción y Error con sus características correspondientes. Unckecked. Ckecked. Error.

A partir de este fragmento de código, escoge la respuesta correcta: void prueba() { try { throw new FileNotFoundException();// Línea 1 } catch (IOException ex) { // Línea 2 // tratamiento excepción, } catch (FileNotFoundException ex2) { // Línea 3 // tratamiento excepción } }. Error de compilación en la línea 1. Error de compilación en la línea 2. Error de compilación en la línea 3.

Escoge la opciones correctas para declarar un MultiCatch. catch(FileNotFoundException|SQLException ex){ //Instrucciones }. catch(FileNotFoundException| IOException ex){ //Instrucciones }. catch(FileNotFoundException, IOException ex){ //Instrucciones }. catch(FileNotFoundException, SQLException ex){ //Instrucciones }.

Dado el siguiente fragmento de código, ¿Cuál será el resultado? public void setEdad(int edad) { // Línea 1 if (edad <= 0) throw new Exception("La edad debe ser positiva."); // Línea 2 this.edad = edad; }. Error de compilación el Línea 1. Error de compilación el Línea 2. No se produce ningún error.

Indica las forma correctas de crear un Try con recursos: try(FileReader fr = new FileReader("datos.txt"); BufferedReader bf=new BufferedReader(fr)){. try(FileReader fr = new FileReader("datos.txt") | BufferedReader bf=new BufferedReader(fr)){. Connection con = DriverManager.getConnection(..); try(con){ }. Connection con = DriverManager.getConnection(..); con = DriverManager.getConnection(..); try(con){ }.

Dado el siguiente código , ¿Qué se mostrará por pantalla? public class myException extends RuntimeException {} public class Test{ public static void main(String[] args){ try{ testMethod(); } catch(myException ex){ System.out.println("Test 1"); } } public static void testMethod(){ //line 1 try{ throw (Math.random()>0.5)?new myException(): new RuntimeException(); } catch(RuntimeException ex){ System.out.println("Test 2"); } } }. Test 1. Test 2. Test 1 Test 2.

Dado el siguiente código , ¿Qué se mostrará por pantalla? public static void main(String[] args) { ArrayList myList=new ArrayList(); String[] mr; try{ while(true){ myList.add(new String("cad")); } } catch(RuntimeException ex){ System.out.println("RuntimeException"); } catch(Exception ex){ System.out.println("Exception"); } System.out.println("End"); }. RuntimeException. Exception. End. Runtime error en el hilo principal.

Denunciar Test