Solucionado (ver solução)
Solucionado
(ver solução)
5
respostas

Erro de compilação

    try(Connection connection = new ConnectionFactory().recuperarConexao()){
        CategoriaDAO categoriaDAO = new CategoriaDAO(connection);
        List<Categoria> listaDeCategorias = categoriaDAO.listar();
        listaDeCategorias.stream().forEach(ct->System.out.println(ct.getNome());

        A ultima linha não compila
5 respostas

Qual a mensagem de erro?

out 05, 2021 8:06:48 PM com.mchange.v2.log.MLog INFORMAÇÕES: MLog clients using java 1.4+ standard logging. out 05, 2021 8:06:49 PM com.mchange.v2.c3p0.C3P0Registry INFORMAÇÕES: Initializing c3p0-0.9.5.4 [built 23-March-2019 23:00:48 -0700; debug? true; trace: 10] out 05, 2021 8:06:49 PM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource INFORMAÇÕES: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1hge136akmy5v3rz0dlne|4b85612c, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> null, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1hge136akmy5v3rz0dlne|4b85612c, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost/loja_virtual?useTimezone=true&serverTimezone=UTC, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {user=**, password=**}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ] Exception in thread "main" java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SLECT ID, ID, NOME FROM CATEGORIA' at line 1 at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953) at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:370) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:67) at dao.CategoriaDAO.listar(CategoriaDAO.java:23) at TestaListagemDeCategorias.main(TestaListagemDeCategorias.java:14)

Esta mensgem no TestaListagemDeCategoria

import java.sql.Connection; import java.sql.SQLException; import java.util.List;

import br.com.alura.jdbc.modelo.Categoria; import dao.CategoriaDAO;

public class TestaListagemDeCategorias {

public static void main(String[] args)throws SQLException {

    try(Connection connection = new ConnectionFactory().recuperarConexao()){
        CategoriaDAO categoriaDAO = new CategoriaDAO(connection);
        List<Categoria> listaDeCategorias = categoriaDAO.listar();
        listaDeCategorias.stream().forEach(ct->System.out.println(ct.getNome()));
solução!

Carlos, pela exceção que vc enviou, parece que o erro está na sua query

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SLECT ID, ID, NOME FROM CATEGORIA'

Em vez de SELECT está SLECT. Você pode alterar e verificar se funciona?

Obrigado João, agora ocorreu certo.