Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import javax.swing.*;
- public class Main {
- public static void main(String[] args) {
- JFrame frame = new JFrame();
- frame.setBounds(128, 128, 800, 600);
- frame.setTitle("Hello");
- frame.setVisible(true);
- frame.setFocusable(true);
- frame.getContentPane().add(new Panel());
- }
- public void action() {
- Connection connect;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- String serverName = "localhost",
- databaseName = "it-learning",
- url = "jdbc:mysql://" + serverName + "/" + databaseName,
- user = "root",
- password = "";
- connect = DriverManager.getConnection(url, user, password);
- int id = (int)(Math.random() * 21) + 1;
- String query = "SELECT * FROM table WHERE id = " + id;
- Statement statement = connect.createStatement();
- ResultSet set = statement.executeQuery(query);
- while (set.next())
- textField.setText(set.getString("text"));
- connect.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement