Advertisement
Guest User

Untitled

a guest
Jan 26th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. package us.Login;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.EventQueue;
  5. import java.sql.*;
  6.  
  7. import javax.swing.JFrame;
  8. import javax.swing.JPanel;
  9. import javax.swing.border.EmptyBorder;
  10. import javax.swing.JLabel;
  11. import javax.swing.JOptionPane;
  12.  
  13. import java.awt.Font;
  14. import javax.swing.JTextField;
  15. import javax.swing.JPasswordField;
  16. import javax.swing.JButton;
  17. import java.awt.event.ActionListener;
  18. import java.awt.event.ActionEvent;
  19.  
  20. public class Login extends JFrame {
  21.  
  22. static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
  23. static final String DB_URL = "jdbc:mysql://sql7.freemysqlhosting.net:3306/sql7275618";
  24. static final String USER = "sql7275618";
  25. static final String PASS = "K6RKaJJ3IY";
  26.  
  27. private JPanel contentPane;
  28. private static JTextField usernamekey;
  29. private static JPasswordField passwordkey;
  30.  
  31. /**
  32. * Launch the application.
  33. */
  34. public static void main(String[] args) {
  35.  
  36.  
  37.  
  38. EventQueue.invokeLater(new Runnable() {
  39. public void run() {
  40. mysql();
  41.  
  42. Login frame = new Login();
  43. frame.setVisible(true);
  44. try {
  45.  
  46. } catch (Exception e) {
  47. e.printStackTrace();
  48. }
  49. }
  50. });
  51. }
  52.  
  53. /**
  54. * Create the frame.
  55. */
  56. public Login() {
  57. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  58. setBounds(100, 100, 319, 395);
  59. contentPane = new JPanel();
  60. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  61. setContentPane(contentPane);
  62. contentPane.setLayout(null);
  63.  
  64. JLabel lblLoginPanel = new JLabel("Login Panel");
  65. lblLoginPanel.setFont(new Font("Slant", Font.PLAIN, 37));
  66. lblLoginPanel.setBounds(65, 11, 228, 50);
  67. contentPane.add(lblLoginPanel);
  68.  
  69. JLabel lblUsername = new JLabel("Username");
  70. lblUsername.setFont(new Font("Source Sans Pro Black", Font.BOLD, 20));
  71. lblUsername.setBounds(20, 153, 119, 50);
  72. contentPane.add(lblUsername);
  73.  
  74. JLabel lblPassword = new JLabel("Password");
  75. lblPassword.setFont(new Font("Source Sans Pro Black", Font.BOLD, 20));
  76. lblPassword.setBounds(20, 214, 219, 22);
  77. contentPane.add(lblPassword);
  78.  
  79. usernamekey = new JTextField();
  80. usernamekey.setBounds(153, 169, 86, 20);
  81. contentPane.add(usernamekey);
  82. usernamekey.setColumns(10);
  83.  
  84. passwordkey = new JPasswordField();
  85. passwordkey.setBounds(153, 215, 86, 22);
  86. contentPane.add(passwordkey);
  87.  
  88. JButton btnNewButton = new JButton("Login");
  89. btnNewButton.addActionListener(new ActionListener() {
  90. public void actionPerformed(ActionEvent arg0) {
  91. try {
  92.  
  93.  
  94.  
  95.  
  96.  
  97. }catch(Exception e) {System.out.print(e);}
  98.  
  99.  
  100. }
  101. });
  102. btnNewButton.setBounds(10, 322, 89, 23);
  103. contentPane.add(btnNewButton);
  104.  
  105. JButton btnReset = new JButton("Reset");
  106. btnReset.setBounds(204, 322, 89, 23);
  107. contentPane.add(btnReset);
  108. }
  109.  
  110. public static void mysql() {
  111. try {
  112. Connection conn = null;
  113. Statement stmt = null;
  114.  
  115. Class.forName("com.mysql.jdbc.Driver");
  116. System.out.println("connecting to the database");
  117.  
  118. conn = DriverManager.getConnection(DB_URL, USER, PASS);
  119. System.out.println("creating a statement..");
  120.  
  121. stmt = conn.createStatement();
  122. String sql="Select * from SimpleLogin where name='"+usernamekey.getText()+"' and pass ='"+passwordkey.getText().toString()+"'";
  123.  
  124. ResultSet rs = stmt.executeQuery(sql);
  125.  
  126. while(rs.next()){
  127.  
  128. }
  129.  
  130.  
  131.  
  132. rs.close();
  133. stmt.close();
  134. conn.close();
  135.  
  136. } catch (SQLException e) {
  137.  
  138. e.printStackTrace();
  139. } catch (Exception e) {
  140. e.printStackTrace();
  141. }
  142. }
  143.  
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement