Estou tentando rodar este código, o banco de dados está povoado , porém ao rodar o código abaixo, terei o seguinte erro:
Exception in thread "main" java.sql.SQLTransientConnectionException: java.net.ConnectException: Connection refused: connect at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) at org.hsqldb.jdbc.JDBCConnection.(Unknown Source) at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source) at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at TestaListagem.main(TestaListagem.java:9) Caused by: org.hsqldb.HsqlException: java.net.ConnectException: Connection refused: connect at org.hsqldb.ClientConnection.openConnection(Unknown Source) at org.hsqldb.ClientConnection.initConnection(Unknown Source) at org.hsqldb.ClientConnection.(Unknown Source) ... 6 more Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) at java.net.AbstractPlainSocketImpl.connect(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.(Unknown Source) at java.net.Socket.(Unknown Source) at org.hsqldb.server.HsqlSocketFactory.createSocket(Unknown Source) ... 9 more
public class TestaListagem {
public static void main(String[] args) throws SQLException {
Connection connection = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/loja-virtual", "SA", "");
Statement stmt = connection.createStatement();
boolean resultado = stmt.execute("select * from Produto");
System.out.println("O resultado foi: " + resultado);
connection.close();
}
}