Boa noite.
Quando compilo TestaListagem.java ocorre o erro:
Exception in thread "main" java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: PRODUTO
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.execute(Unknown Source)
at br.com.caelum.jdbc.TestaListagem.main(TestaListagem.java:38)
Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: PRODUTO
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.ParserDQL.readTableName(Unknown Source)
at org.hsqldb.ParserDQL.readTableOrSubquery(Unknown Source)
at org.hsqldb.ParserDQL.XreadTableReference(Unknown Source)
at org.hsqldb.ParserDQL.XreadFromClause(Unknown Source)
at org.hsqldb.ParserDQL.XreadTableExpression(Unknown Source)
at org.hsqldb.ParserDQL.XreadQuerySpecification(Unknown Source)
at org.hsqldb.ParserDQL.XreadSimpleTable(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryPrimary(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryTerm(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryExpressionBody(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryExpression(Unknown Source)
at org.hsqldb.ParserDQL.compileCursorSpecification(Unknown Source)
at org.hsqldb.ParserCommand.compilePart(Unknown Source)
at org.hsqldb.ParserCommand.compileStatements(Unknown Source)
at org.hsqldb.Session.executeDirectStatement(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 3 more
Meu código:
package br.com.caelum.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class TestaListagem {
public static void main(String[] args) throws SQLException {
Connection connection = DriverManager.getConnection("jdbc:hsqldb:hsql//localhost/loja-virtual", "SA", "");
Statement statement = connection.createStatement();
boolean resultado = statement.execute("select * from Produto");
System.out.println(resultado);
connection.close();
}
}
O interessante é que quando rodo a classe TestaConexão.java não ocorre nenhum erro. E também quando executo o select direto no manager do HSQL eu obtenho o resultado dos itens inseridos.
Aguardo resposta atenciosamente,