⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mydb.java

📁 含有图形化界面
💻 JAVA
字号:
package com.zsf.manager;

import java.sql.*;

public class MyDB {
	private static final String database = "mydb";
	private static final String user = "root";
	private static final String password = "123456";
	
	private Connection connection;
	private Statement statement;
	
	public void openConnection() throws SQLException {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://localhost/" + database;
			connection = DriverManager.getConnection(url, user, password);
			statement = connection.createStatement();
		} catch (ClassNotFoundException e) {
			throw new SQLException(e.getMessage());
		}
	}
	
	public void closeConnection() {
		try {
			if (statement != null) statement.close();
			if (connection != null) connection.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public int executeUpdate(String sql) throws SQLException {
		return statement.executeUpdate(sql);
	}
	
	public ResultSet executeQuery(String sql) throws SQLException {
		return statement.executeQuery(sql);
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -