[Figura: trecho de código Java com linhas numeradas]
1 package com.sun.j2ee.blueprints.signon.dao;
2 import java.util.*;
3 import java.sql.*;
4 import javax.sql.*;
5 import javax.naming.*;
6 import com.sun.j2ee.blueprints.util.tracer.*;
7 import com.sun.j2ee.blueprints.util.dao.*;
8 public class PointbaseUserDAO implements UserDAO {
9 private final static String MATCH_PASSWORD_QUERY =
10 "SELECT password FROM " + DatabaseNames.SIGNON_TABLE +
11 " WHERE username = ?";
12 private final static String CREATE_USER_QUERY = "INSERT INTO " +
13 DatabaseNames.SIGNON_TABLE + " VALUES(?, ?)";
14 public void createUser(String userName, String password)
15 throws SignOnDAODupKeyException {
16 Connection conn = null; PreparedStatement ps = null;
17 try {
18 conn = DAOUtils.getDBConnection(JNDINames.SIGNON_DATASOURCE);
19 ps = conn.prepareStatement(CREATE_USER_QUERY);
20 ps.setString(1, userName.trim());
21 ps.setString(2, password.trim());
22 int result = ps.executeUpdate();
23 if(result != 1) {
24 throw new SignOnDAODupKeyException("Unable to create user. " +
25 "Duplicate Key : " + userName);
26 }
27 } catch (SQLException se) {
28 throw new DAOSystemException(se);
29 } finally {
30 DAOUtils.closeStatement(ps);
31 DAOUtils.closeConnection(conn);
32 }
33 }
34 }
Considerando o trecho de código acima, escrito na linguagem Java, adaptado de java.sun.com, julgue os itens a seguir
1 package com.sun.j2ee.blueprints.signon.dao;
2 import java.util.*;
3 import java.sql.*;
4 import javax.sql.*;
5 import javax.naming.*;
6 import com.sun.j2ee.blueprints.util.tracer.*;
7 import com.sun.j2ee.blueprints.util.dao.*;
8 public class PointbaseUserDAO implements UserDAO {
9 private final static String MATCH_PASSWORD_QUERY =
10 "SELECT password FROM " + DatabaseNames.SIGNON_TABLE +
11 " WHERE username = ?";
12 private final static String CREATE_USER_QUERY = "INSERT INTO " +
13 DatabaseNames.SIGNON_TABLE + " VALUES(?, ?)";
14 public void createUser(String userName, String password)
15 throws SignOnDAODupKeyException {
16 Connection conn = null; PreparedStatement ps = null;
17 try {
18 conn = DAOUtils.getDBConnection(JNDINames.SIGNON_DATASOURCE);
19 ps = conn.prepareStatement(CREATE_USER_QUERY);
20 ps.setString(1, userName.trim());
21 ps.setString(2, password.trim());
22 int result = ps.executeUpdate();
23 if(result != 1) {
24 throw new SignOnDAODupKeyException("Unable to create user. " +
25 "Duplicate Key : " + userName);
26 }
27 } catch (SQLException se) {
28 throw new DAOSystemException(se);
29 } finally {
30 DAOUtils.closeStatement(ps);
31 DAOUtils.closeConnection(conn);
32 }
33 }
34 }
Considerando o trecho de código acima, escrito na linguagem Java, adaptado de java.sun.com, julgue os itens a seguir
A classe PointbaseUserDAO possui um construtor vazio implicitamente declarado.
CertoErrado