Enviado em 30/06/2021 - 00:25h
Olá pessoal
SELECT * FROM BANCO.UNTITLED FETCH FIRST 100 ROWS ONLY;
INSERT INTO BANCO.UNTITLED (SALDO, DEPOSITO, CREDITADO, SALDO_FINAL)
VALUES (300.0, 200.0, 100.0, 400.0);
esses valores eu usei como exemplo
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>Conta</h1>
<form method="post" action="teste.jsp">
Saldo inicial<input type="text" name="saldo"><br>
Debitar <input type="text" name="debito"><br>
Creditar <input type="text" name="credito"><br>
<input type="submit" value="Entrar">
</form>
</body>
</html>
public class Banco {
private double saldoincial;
private double saldo;
private double depositar;
private double debitar;
private double credito;
private double value;
private double saldofinal;
public Banco() {
// if(saldoincial > 0.0){
// saldo = saldoincial;
// }
}
public double credit () {
credito = saldo +depositar ;
//System.out.printf("Saldo Agora é: $%.2f \n",saldo );
return credito;
}
public double getSaldo() {
return saldo;
}
public void setSaldo(double saldo) {
this.saldo = saldo;
}
public boolean debit() {
if(credito - debitar >= 0.0) {
saldofinal = saldo - debitar;
return true;
} else
return false;
}
public double SaldoFinal() {
debit();
return saldofinal;
}
public double getDepositar() {
return depositar;
}
public void setDepositar(double depositar) {
this.depositar = depositar;
}
public double getDebitar() {
return debitar;
}
public void setDebitar(double debitar) {
this.debitar = debitar;
}
public double getCredito() {
return credito;
}
public void setCredito(double credito) {
this.credito = credito;
}
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
public double getSaldoincial() {
return saldoincial;
}
public void setSaldoincial(double saldoincial) {
this.saldoincial = saldoincial;
}
@Override
public String toString() {
return "Banco\n"
+"Saldo Inicial= "+saldo
+"\nFoi Depositado= "+getDepositar()
+"\nSaldo Atual=" + credit()
+"\nFoi retirado= "+getDebitar()
+"\nSaldoFinal=" + saldofinal;
//+"\nSaldoFinal=" + SaldoFinal();
}
public double getSaldofinal() {
return saldofinal;
}
public void setSaldofinal(double saldofinal) {
this.saldofinal = saldofinal;
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
public class BancoDAO {
String uri = "jdbc:derby://localhost:1527/BancoMuitaGrana";
Connection con;
public BancoDAO(){
connect();
}
public void connect(){
try {
con = DriverManager.getConnection(uri, "Banco", "123");
} catch (Exception e) {
e.printStackTrace();
}
}
public List<Banco>getbanco(){
// String sql = "SELECT * FROM BANCO.UNTITLED";
List<Banco> Banc = new ArrayList<>();
Banco b;
try {
Statement stmt = con.createStatement();
String sql = "SELECT * FROM BANCO.UNTITLED";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
b = new Banco();
b.setSaldo(rs.getDouble("SALDO"));
b.setDepositar(rs.getDouble("DEPOSITO"));
b.setDebitar(rs.getDouble("CREDITADO"));
b.setSaldofinal(rs.getDouble("SALDO_FINAL"));
Banc.add(b);
}
} catch (Exception e) {
e.printStackTrace();
}
return Banc;
}
}