Guest User

Untitled

a guest
Feb 26th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. package br.com.Sistema.dal;
  2.  
  3. import java.sql.*;
  4. public class ModuloConexao {
  5. //metodo por estabelecer conexao com o banco
  6. public static Connection conector() {
  7. java.sql.Connection conexao = null;
  8.  
  9. // linha abaixo "chama" o driver
  10. String driver = "com.mysql.jdbc.Driver";
  11.  
  12. // armazenando informaçoes referente ao bd
  13. String url = "jdbc:mysql://localhost:3306/teste";
  14. String user = "root";
  15. String pass = "vertrigo";
  16.  
  17. // Estabecendo conexao ao Banco de Dados
  18. try {
  19. Class.forName(driver);
  20. conexao = DriverManager.getConnection(url, user, pass);
  21. System.out.println(conexao);
  22. return conexao;
  23. } catch (Exception e) {
  24. // a linha abaixo serve de apoio para esclarecer o erro
  25. //JOptionPane.showMessageDialog(null,"Não há Conexao com o Banco de Dados");
  26. return null;
  27.  
  28. }
  29.  
  30.  
  31. }
  32. }
  33.  
  34. package TelaPrincipal.telas;
  35.  
  36.  
  37.  
  38.  
  39. import java.awt.EventQueue;
  40. import javax.swing.JFrame;
  41. import javax.swing.JPanel;
  42. import javax.swing.border.EmptyBorder;
  43. import javax.swing.JLabel;
  44. import java.awt.Font;
  45. import javax.swing.JTextField;
  46. import javax.swing.SwingConstants;
  47. import javax.swing.ImageIcon;
  48. import javax.swing.JButton;
  49.  
  50.  
  51. import java.sql.*;
  52. import br.com.Sistema.dal.ModuloConexao;
  53.  
  54.  
  55. public class TelaLogin extends javax.swing.JFrame {
  56.  
  57. Connection conexao = null;
  58. PreparedStatement pst = null;
  59. ResultSet rs = null;
  60.  
  61. private JPanel contentPane;
  62. private JTextField textField;
  63. private JTextField textField_1;
  64.  
  65. /**
  66. * Launch the application.
  67. */
  68. public static void main(String[] args) {
  69. EventQueue.invokeLater(new Runnable() {
  70. public void run() {
  71. try {
  72. TelaLogin frame = new TelaLogin();
  73. frame.setVisible(true);
  74. frame.setLocationRelativeTo(null);
  75. } catch (Exception e) {
  76. e.printStackTrace();
  77. }
  78. }
  79. });
  80. }
  81.  
  82. /**
  83. * Create the frame.
  84. */
  85. public TelaLogin() {
  86. conexao = ModuloConexao.conector();
  87. System.out.println(conexao);
  88.  
  89. setResizable(false);
  90. setTitle(" < Sistema de Usuario >");
  91. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  92. setBounds(100, 100, 330, 191);
  93. contentPane = new JPanel();
  94. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  95. setContentPane(contentPane);
  96. contentPane.setLayout(null);
  97.  
  98.  
  99. JLabel lblUsurio = new JLabel("Usuario");
  100. lblUsurio.setHorizontalAlignment(SwingConstants.RIGHT);
  101. lblUsurio.setFont(new Font("Tahoma", Font.BOLD, 12));
  102. lblUsurio.setBounds(8, 17, 62, 26);
  103. contentPane.add(lblUsurio);
  104.  
  105. JLabel lblSenha = new JLabel("Senha");
  106. lblSenha.setHorizontalAlignment(SwingConstants.RIGHT);
  107. lblSenha.setFont(new Font("Tahoma", Font.BOLD, 12));
  108. lblSenha.setBounds(20, 54, 50, 26);
  109. contentPane.add(lblSenha);
  110.  
  111. textField = new JTextField();
  112. textField.setBounds(92, 21, 176, 20);
  113. contentPane.add(textField);
  114. textField.setColumns(10);
  115.  
  116. textField_1 = new JTextField();
  117. textField_1.setColumns(10);
  118. textField_1.setBounds(92, 52, 176, 20);
  119. contentPane.add(textField_1);
  120.  
  121. JLabel lblConectado = new JLabel("");
  122. lblConectado.setIcon(new ImageIcon("C:\ambiente_de_trabalho\teste\Inbras\src\br\com\inbras\icones\desconectado1.png"));
  123. lblConectado.setBounds(30, 91, 33, 33);
  124. contentPane.add(lblConectado);
  125.  
  126. JButton btnLogin = new JButton("Login");
  127. btnLogin.setBounds(92, 101, 176, 23);
  128. contentPane.add(btnLogin);
  129.  
  130. }
  131. }
Add Comment
Please, Sign In to add comment