Guest User

Untitled

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