Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package controle;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import javax.swing.JOptionPane;
- import modelo.ModeloTelefone;
- /**
- *
- * @author andhakai
- */
- public class ControleTelefone {
- ConectaBanco connex = new ConectaBanco();
- ModeloTelefone mod = new ModeloTelefone();
- public void inserir (ModeloTelefone mod){
- connex.conexao();
- try{
- PreparedStatement pst = connex.conn.prepareStatement("insert into telefone(numero_tel)values(?)");
- pst.setString(1, mod.getTel());
- pst.execute();
- JOptionPane.showMessageDialog(null, "dados inseridos com sucesso!");
- }catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "erro de conexão 01 ! "+ ex.getMessage());
- }
- connex.desconecta();
- }
- public void alterar(ModeloTelefone mod){
- connex.conexao();
- PreparedStatement pst;
- try{
- pst = connex.conn.prepareStatement("update telefone set numero_tel=? where id_telefone=?");
- pst.setString(1, mod.getTel());
- pst.setInt(2, mod.getCod());
- pst.execute();
- JOptionPane.showMessageDialog(null, "dados alterados com sucesso!");
- }catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "erro de conexão 02 ! "+ ex.getMessage());
- }
- connex.desconecta();
- }
- public void Excluir(ModeloTelefone mod){
- connex.conexao();
- PreparedStatement pst;
- try{
- pst = connex.conn.prepareStatement("delete from telefone where id_telefone?");
- pst.setInt(1,mod.getCod());
- pst.execute();
- JOptionPane.showMessageDialog(null,"dados excluidos com sucesso");
- }catch(SQLException ex){
- JOptionPane.showMessageDialog(null,"erro ao excluir");
- }
- }
- public ModeloTelefone primeiro(){
- connex.conexao();
- connex.execultaSQL("select * from telefone");
- try{
- connex.rs.first();
- mod.setCod(connex.rs.getInt("id_telefone"));
- mod.setTel(connex.rs.getString("numero_tel"));
- }catch(SQLException ex){
- JOptionPane.showMessageDialog(null, "erro 01\n"+ex);
- }
- connex.desconecta();
- return mod;
- }
- public ModeloTelefone ultimo(){
- connex.conexao();
- // connex.execultaSQL("select * from telefone");
- try{
- connex.rs.last();
- mod.setCod(connex.rs.getInt("id_telefone"));
- mod.setTel(connex.rs.getString("numero_tel"));
- }catch(SQLException ex){
- JOptionPane.showMessageDialog(null, "erro 01\n"+ex);
- }
- connex.desconecta();
- return mod;
- }
- public ModeloTelefone proximo(){
- connex.conexao();
- connex.execultaSQL("select * from telefone");
- try{
- connex.rs.previous();
- mod.setCod(connex.rs.getInt("id_telefone"));
- mod.setTel(connex.rs.getString("numero_tel"));
- }catch(SQLException ex){
- JOptionPane.showMessageDialog(null, "erro 01\n"+ex);
- }
- connex.desconecta();
- return mod;
- }
- public ModeloTelefone anterior(){
- connex.conexao();
- connex.execultaSQL("select * from telefone");
- try{
- connex.rs.next();
- mod.setCod(connex.rs.getInt("id_telefone"));
- mod.setTel(connex.rs.getString("numero_tel"));
- }catch(SQLException ex){
- JOptionPane.showMessageDialog(null, "erro 01\n"+ex);
- }
- connex.desconecta();
- return mod;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement