Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Dúvida no Ex. 3 da Aula 5 - Connection Pool e Datasources

O meu esta dando erro!!!

package br.com.caelum.jdbc;

import java.sql.Connection; import java.sql.SQLException;

import javax.sql.DataSource;

import org.hsqldb.jdbc.JDBCPool;

public class ConnectionPool {

private DataSource dataSource;

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{

//Connection conexao = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/loja-virtual", "SA", ""); Connection conexao = dataSource.getConnection(); return conexao;

} }

import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement;

public class TestaListagem {

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

Connection conexao = new ConnectionPool().getConnection();

Statement statement = conexao.createStatement(); boolean result = statement.execute("select * from Produto"); ResultSet resultSet = statement.getResultSet();

while(resultSet.next()){ int id = resultSet.getInt("id"); String nome = resultSet.getString("nome"); String descricao = resultSet.getString("descricao"); System.out.println(id + "; Nome: " + nome + "; Decricao: "+ descricao); }

resultSet.close(); statement.close();

conexao.close(); }

}

Exception in thread "main" java.lang.NullPointerException at org.hsqldb.DatabaseURL.parseURL(Unknown Source) at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source) at org.hsqldb.jdbc.pool.JDBCPooledDataSource.getPooledConnection(Unknown Source) at org.hsqldb.jdbc.JDBCPool.getConnection(Unknown Source) at br.com.caelum.jdbc.ConnectionPool.getConnection(ConnectionPool.java:26) at br.com.caelum.jdbc.TestaListagem.main(TestaListagem.java:12)

1 resposta
solução!

Ja achei o erro!!!! é so trocar: pool.setURL("jdbc:hsqldb:hsql://localhost/loja-virtual"); por pool.setUrl("jdbc:hsqldb:hsql://localhost/loja-virtual");