Bom tarde pessoal, estou com problemas com jdbc, o codigo não apresenta erro, mas não está inserindo e nem removendo, apenas listando, vou por o codigo para vcs, valeu abraço
package conexao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DataBase {
static Connection getConnection() throws SQLException {
Connection connection = DriverManager
.getConnection("jdbc:hsqldb:file:C:/Users/julian/Desktop/hypersql/loja-virtual", "SA", "1234");
return connection;
}
}
package conexao;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
public class TestaRemocao {
public static void main(String[] args) throws SQLException {
Connection connection = DataBase.getConnection();
Statement stmt = connection.createStatement();
stmt.execute("delete from produto where id > 3");
int count = stmt.getUpdateCount();
System.out.println(count + "linhas atualizadas");
connection.close();
}
}
package conexao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TestaInsercao {
public static void main(String[] args) throws SQLException {
Connection connection = DataBase.getConnection();
Statement statement = connection.createStatement();
boolean resultado = statement.execute("insert into produto(nome, descricao)values('Notebook', 'Notebook i5')",
Statement.RETURN_GENERATED_KEYS);
System.out.println(resultado);
ResultSet resultset = statement.getGeneratedKeys();
while(resultset.next()) {
String id = resultset.getString("id");
System.out.println(id + "gerado");
}
statement.close();
connection.close();
}
}