daily pastebin goal
29%
SHARE
TWEET

Action

far_light Mar 17th, 2018 183 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. import javax.swing.*;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         JFrame frame = new JFrame();
  9.         frame.setBounds(128, 128, 800, 600);
  10.         frame.setTitle("Hello");
  11.         frame.setVisible(true);
  12.  
  13.         frame.setFocusable(true);
  14.         frame.getContentPane().add(new Panel());
  15.     }
  16.  
  17.     public void action() {
  18.         Connection connect;
  19.  
  20.         try {
  21.             Class.forName("com.mysql.jdbc.Driver");
  22.  
  23.             String serverName = "localhost",
  24.                     databaseName = "it-learning",
  25.                     url  = "jdbc:mysql://" + serverName + "/" + databaseName,
  26.                     user = "root",
  27.                     password = "";
  28.  
  29.             connect = DriverManager.getConnection(url, user, password);
  30.             int id = (int)(Math.random() * 21) + 1;
  31.             String query = "SELECT * FROM table WHERE id = " + id;
  32.             Statement statement = connect.createStatement();
  33.             ResultSet set = statement.executeQuery(query);
  34.  
  35.             while (set.next())
  36.                 textField.setText(set.getString("text"));
  37.  
  38.             connect.close();
  39.         } catch (Exception e) {
  40.             e.printStackTrace();
  41.         }
  42.     }
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top