Advertisement
Guest User

Untitled

a guest
Jan 28th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. package com.mati.webrestaurant.webrestaurant;
  2.  
  3.  
  4. import org.springframework.boot.SpringApplication;
  5. import org.springframework.boot.autoconfigure.SpringBootApplication;
  6.  
  7. import javax.swing.*;
  8. import java.awt.*;
  9. import java.awt.event.ActionEvent;
  10. import java.awt.event.ActionListener;
  11. import java.sql.*;
  12.  
  13. @SpringBootApplication
  14. public class WebRestaurantApplication{
  15.  
  16. public static void main(String[] args){
  17.  
  18. String url = "jdbc:mysql://localhost:3306/restaurant?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
  19. String pass = "admin";
  20. String login ="root";
  21. try {
  22. Connection con = DriverManager.getConnection(url, login, pass);
  23. Statement statemet = con.createStatement();
  24. ResultSet resultSet = statemet.executeQuery("select dish_name from dish");
  25. StringBuilder result = new StringBuilder();
  26. JTextArea textArea = new JTextArea();
  27. textArea.setPreferredSize(new Dimension(400,400));
  28. while(resultSet.next()){
  29. result.append(resultSet.getString("dish_name")).append("\n");
  30. }
  31.  
  32. JFrame frame = new JFrame("frame");
  33. frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
  34. frame.setLayout(new FlowLayout());
  35. frame.add(textArea);
  36. frame.setSize(new Dimension(400,400));
  37. JButton button = new JButton("GetDishes");
  38. button.setPreferredSize(new Dimension(50,20));
  39. button.setMaximumSize(new Dimension(50,20));
  40. frame.add(button);
  41. frame.pack();
  42. frame.setVisible(true);
  43. button.addActionListener(new ActionListener() {
  44. @Override
  45. public void actionPerformed(ActionEvent e) {
  46. System.out.println(result.toString());
  47. textArea.setText(result.toString());
  48. }
  49. });
  50.  
  51. }catch (Exception e){
  52. System.out.println("Nie udalo sie polaczyc z baz");
  53. e.printStackTrace();
  54. }
  55.  
  56. SpringApplication.run(WebRestaurantApplication.class, args);
  57.  
  58.  
  59.  
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement