Estou com o mesma mensagem de erro em minha aplicação. Entro em minha pasta do projeto via terminal cd Downloads/loja-virtual E lá dentro digito para subir o banco
java -cp hsqldb.jar org.hsqldb.server.Server --database.0 file:loja-virtual --dbname.0 loja-virtual
depois com o CTRL + SHIFT +T abro uma nova aba no terminal ainda dentro da minha pasta do projeto e digito o seguinte comando:
java -cp hsqldb.jar org.hsqldb.util.DatabaseManager
E escolho a seguinte opção: Type: HSQL Database Engine Server com a seguinte url: jdbc:hsqldb:hsql://localhost/loja-virtual
e ao tentar inserir via java na classe de teste de inserção tomo a mensagem de erro informada na stack abaixo.
E a minha stacktrace.
adquirindo conexão...Exception in thread "main" java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: CATEGORIA
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
at br.com.caelum.jdbc.CategoriasDAO.lista(CategoriasDAO.java:25)
at br.com.caelum.jdbc.TestaCategorias.main(TestaCategorias.java:17)
Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: CATEGORIA
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.SchemaManager.getTable(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.compileStatement(Unknown Source)
at org.hsqldb.Session.compileStatement(Unknown Source)
at org.hsqldb.StatementManager.compile(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 4 more
Segue minha classe de conexão.
public class ConnectionPool {
private DataSource dataSource;
public ConnectionPool() {
JDBCPool pool = new JDBCPool();
pool.setUrl("jdbc:hsqldb:hsql//localhost/loja-virtual");
pool.setUser("SA");
pool.setPassword("");
this.dataSource = pool;
}
Connection getConnection() throws SQLException {
System.out.print("adquirindo conexão...");
Connection connection = dataSource.getConnection();
return connection;
}
}
Classe de Teste de Inserção
public class TestaInsercao {
public static void main(String[] args) throws Exception {
try (Connection connection = new ConnectionPool().getConnection()) {
connection.setAutoCommit(false);
String sql = "insert into Produto (nome, descricao) values (?, ?)";
try (PreparedStatement statement = connection.prepareStatement(sql,
Statement.RETURN_GENERATED_KEYS)) {
adiciona("TV LCD", "32 polegadas", statement);
adiciona("Blueray", "Full HDMI", statement);
connection.commit();
statement.close();
} catch (Exception e) {
connection.rollback();
System.out.println("Rollback efetuado");
e.printStackTrace();
}
}
}
private static void adiciona(String nome, String descricao,
PreparedStatement statement) throws SQLException {
// if (nome.equals("Blueray")) {
// throw new IllegalArgumentException("Problema ocorrido");
// }
statement.setString(1, nome);
statement.setString(2, descricao);
boolean resultado = statement.execute();
System.out.println(resultado);
try (ResultSet generatedKeys = statement.getGeneratedKeys()) {
while (generatedKeys.next()) {
long id = generatedKeys.getLong("id");
System.out.println("id gerado: " + id);
}
}
}
}
Como corrijo isso?