Advertisement
Guest User

Untitled

a guest
Jun 17th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. package ModeloConection;
  2.  
  3. import java.sql.*;
  4.  
  5. import java.sql.Connection;
  6. import java.sql.ResultSet;
  7. import java.util.logging.Level;
  8. import java.util.logging.Logger;
  9. import java.sql.SQLException;
  10. import java.sql.Statement;
  11. import javax.swing.JOptionPane;
  12.  
  13.  
  14.  
  15. public class ConexãoBD {
  16.  
  17. public static PreparedStatement stm ;
  18. public static ResultSet rs ;
  19. public static Connection con ;
  20. private String driver = "com.mysql.jdbc.Driver";
  21. private String caminho = "jdbc:mysql://localhost:3306/hamburgueria";
  22. private String usuario = "root";
  23. private String senha = "";
  24.  
  25.  
  26.  
  27. public void conexao(){
  28. try {
  29. String setProperty = System.setProperty("jbdc.Driver", driver );
  30. con = (Connection) DriverManager.getConnection(caminho , usuario , senha );
  31. // JOptionPane.showMessageDialog(null, "Conexão efetuada com sucesso");
  32. } catch (SQLException ex) {
  33. JOptionPane.showMessageDialog(null, "Erro ao se conectar ao banco de dados:\n"+ex);
  34. }
  35. }
  36.  
  37. public void executaSql(String sql){
  38. try {
  39. Statement stm = con.createStatement(rs.TYPE_SCROLL_INSENSITIVE,rs.CONCUR_READ_ONLY);
  40. rs = stm.executeQuery(sql);
  41. } catch (SQLException ex) {
  42. JOptionPane.showMessageDialog(null, "Erro ExecutaSQL :\n"+ex);
  43. }
  44.  
  45.  
  46. }
  47.  
  48. public void desconecta(){
  49. try {
  50. con.close();
  51. } catch (SQLException ex) {
  52. Logger.getLogger(ConexãoBD.class.getName()).log(Level.SEVERE, null, ex);
  53. }
  54.  
  55. }
  56.  
  57.  
  58.  
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement