Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. package project;
  2.  
  3. public class Project {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. // FrameInput frame = new FrameInput();
  8.  
  9. DatabaseQuery query = new DatabaseQuery();
  10. }
  11.  
  12. }
  13.  
  14. ----
  15.  
  16. package project;
  17.  
  18. import java.awt.BorderLayout;
  19. import java.awt.GridLayout;
  20. import javax.swing.*;
  21.  
  22. public class FrameInput extends JFrame {
  23. // behaviours
  24. private GridLayout layoutPanelInput;
  25. // panelInput
  26. private JPanel panelInput;
  27. private JTextField inputName;
  28. private JTextField inputPass;
  29. // other
  30. private JButton buttonInput;
  31. private JLabel labelResult;
  32.  
  33. public FrameInput() {
  34.  
  35. initComponents();
  36.  
  37. this.setTitle("window name");
  38. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  39. this.setSize(200, 150);
  40. this.setVisible(true);
  41. }
  42.  
  43. private void initComponents() {
  44.  
  45. layoutPanelInput = new GridLayout(2,1);
  46.  
  47. panelInput = new JPanel(layoutPanelInput);
  48. inputName = new JTextField();
  49. inputPass = new JTextField();
  50. panelInput.add(inputName);
  51. panelInput.add(inputPass);
  52.  
  53. buttonInput = new JButton("Search");
  54. labelResult = new JLabel("PLACEHOLDER");
  55.  
  56. this.add(labelResult, BorderLayout.PAGE_START);
  57. this.add(panelInput, BorderLayout.CENTER);
  58. this.add(buttonInput, BorderLayout.PAGE_END);
  59. }
  60. }
  61.  
  62. ----
  63.  
  64. package project;
  65.  
  66. import java.sql.Connection;
  67. import java.sql.DriverManager;
  68. import java.sql.SQLException;
  69.  
  70. public class DatabaseQuery {
  71.  
  72. public DatabaseQuery() {
  73.  
  74. initLiterals();
  75. try {
  76. Class.forName("com.mysql.jdbc.Driver");
  77.  
  78. con = DriverManager.getConnection(dbURL, dbUser, dbName);
  79. System.out.println("Got connection");
  80. }
  81. catch(ClassNotFoundException e) {
  82. System.out.println("ERROR: Driver not found");
  83. e.printStackTrace(System.out);
  84. }
  85. catch(SQLException e) {
  86. System.out.println("ERROR: Connection not established");
  87. e.printStackTrace(System.out);
  88. }
  89. // finally {
  90. // try {
  91. // con.close();
  92. // }
  93. // catch(SQLException e) {
  94. // System.out.println("Task faile successfully");
  95. // e.printStackTrace(System.out);
  96. // }
  97. // }
  98. }
  99.  
  100. private void initLiterals() {
  101. dbHost = "localhost";
  102. dbPort = "3306";
  103. dbName = "new_schema";
  104. dbURL = "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName;
  105.  
  106. dbUser = "root";
  107. dbPass = "root";
  108. dbTable = "student";
  109. }
  110.  
  111. String dbUser, dbPass, dbHost, dbPort, dbName, dbURL, dbTable;
  112.  
  113. Connection con = null;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement