写一个JAVA连接数据库的交互界面
时间: 2023-07-20 19:20:13 浏览: 53
好的,以下是一个简单的Java连接MySQL数据库的交互界面示例:
```java
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DBConnectionDemo extends JFrame implements ActionListener {
// 数据库连接参数
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost:3306/mydb";
static final String USER = "root";
static final String PASS = "password";
// GUI组件
JLabel titleLabel, nameLabel, ageLabel, genderLabel;
JTextField nameField, ageField, genderField;
JButton addButton, clearButton;
JTextArea resultArea;
// 数据库连接对象
Connection conn = null;
Statement stmt = null;
public DBConnectionDemo() {
// 设置界面
super("数据库交互界面");
setSize(400, 400);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new BorderLayout());
// 添加标题
titleLabel = new JLabel("添加用户信息");
titleLabel.setHorizontalAlignment(S
相关推荐
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)