-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCarroDao.java
42 lines (29 loc) · 1.42 KB
/
CarroDao.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package DAO;
import Classes.Carro;
import classesBase.AcessoMySQL;
import java.sql.SQLException;
public class CarroDao extends AcessoMySQL {
public CarroDao(String nomeBanco, String usuario) {
super(nomeBanco, usuario);
}
public void insere(Carro c) throws SQLException{
this.getConnection();
c.setCodigoCarro(this.GetNextId("carro", "codigocarro"));
String sql= "insert into carro(codigocarro,modelo,fabricante,anofabricacao,portas,"
+ "tipocombustivel,valor) values(?,?,?,?,?,?,?)";
this.executeCommand(sql, c.getCodigoCarro(),c.getModelo(),c.getFabricante(),
c.getAnoFabricacao(),c.getPortas(),c.getTipoCombustivel(),c.getValor());
}
public void muda(Carro c) throws SQLException{
this.getConnection();
String sql = "update carro set codigocarro = ?, modelo = ?,"+
"fabricante = ?, anofabricacao= ? ,portas = ?, tipocombustivel = ?,valor = ?";
this.executeCommand(sql, c.getCodigoCarro(),c.getModelo(),c.getFabricante(),
c.getAnoFabricacao(),c.getPortas(),c.getTipoCombustivel(),c.getValor());
}
public void deleta(int codigocarro) throws SQLException{
this.getConnection();
String sql = "delete from carro where codigocarro =?";
this.executeCommand(sql, codigocarro);
}
}