日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

IDEA 鏈接Mysql數據庫并執行查詢操作的完整代碼

瀏覽:13日期:2023-10-18 08:41:51

1、先寫個 Mysql 的鏈接設置頁面

package com.wretchant.fredis.menu.mysql;import com.intellij.notification.NotificationType;import com.intellij.openapi.actionSystem.AnAction;import com.intellij.openapi.actionSystem.AnActionEvent;import com.wretchant.fredis.gui.dialog.TableDialog;import com.wretchant.fredis.util.NotifyUtils;import com.wretchant.fredis.util.PropertiesUtils;import org.jetbrains.annotations.NotNull;import javax.swing.*;import java.util.Map;import java.util.Properties;/** * @author Created by 譚健 on 2020/8/26. 星期三. 15:24. * © All Rights Reserved. */public class MysqlConfig extends AnAction { @Override public void actionPerformed(@NotNull AnActionEvent event) {Properties properties = PropertiesUtils.readFromSystem();if (properties != null) { TableDialog.TableField build = TableDialog.TableField.build(properties.stringPropertyNames()); TableDialog dialog = new TableDialog('Mysql 連接配置', build); for (int i = 0; i < dialog.getLabels().size(); i++) {JLabel label = dialog.getLabels().get(i);JTextField textField = dialog.getInputs().get(i);String property = properties.getProperty(label.getText());textField.setText(property); } dialog.show(); if (dialog.isOK()) {Map<String, String> valueMap = dialog.getValueMap();valueMap.forEach(properties::setProperty);PropertiesUtils.write2System(properties); }} else { NotifyUtils.notifyUser(event.getProject(), '讀取配置文件失敗,配置文件不存在', NotificationType.ERROR);} }}

IDEA 鏈接Mysql數據庫并執行查詢操作的完整代碼

2、然后簡單的寫個 JDBC 操作數據庫的支持類

package com.wretchant.fredis.support;import cn.hutool.core.util.StrUtil;import com.intellij.notification.NotificationType;import com.intellij.openapi.actionSystem.AnActionEvent;import com.intellij.openapi.actionSystem.PlatformDataKeys;import com.intellij.openapi.editor.SelectionModel;import com.wretchant.fredis.util.ClipboardUtils;import com.wretchant.fredis.util.NotifyUtils;import com.wretchant.fredis.util.PropertiesUtils;import com.wretchant.fredis.value.StringValue;import org.apache.commons.lang.StringUtils;import org.jetbrains.annotations.NotNull;import java.sql.*;import java.util.*;/** * @author Created by 譚健 on 2020/8/12. 星期三. 17:42. * © All Rights Reserved. */public class Mysql { /** * 執行查詢語句的返回結果 */ public static class Rs {public Rs(List<Map<String, Object>> r) { this.r = r; this.count = r.size();}private List<Map<String, Object>> r = new ArrayList<>();private int count;public List<Map<String, Object>> getR() { return r;}public void setR(List<Map<String, Object>> r) { this.r = r;}public int getCount() { return count;}public void setCount(int count) { this.count = count;}public Map<String, Object> one() { if (Objects.isNull(r) || r.isEmpty()) {return null; } return r.get(0);}public Object oneGet(String key) { return one().get(key);} } // 參考: https://www.cnblogs.com/jyroy/p/9637149.html public static class JDBCUtil {/** * 執行sql 并返回 map 數據 * * @param sql * @return */public static Rs rs(String sql) { Connection connection = null; Statement statement = null; ResultSet resultSet = null; List<Map<String, Object>> r = new ArrayList<>(); try {connection = Mysql.DatabaseUtils.getConnection();statement = connection.createStatement();resultSet = statement.executeQuery(sql);// 基礎信息ResultSetMetaData metaData = resultSet.getMetaData();// 返回了多少個字段int columnCount = metaData.getColumnCount();while (resultSet.next()) { Map<String, Object> valueMap = new LinkedHashMap<>(); for (int i = 0; i < columnCount; i++) {// 這個字段是什么數據類型String columnClassName = metaData.getColumnClassName(i);// 字段名稱String columnName = metaData.getColumnName(i);Object value = resultSet.getObject(columnName);valueMap.put(columnName, value); } r.add(valueMap);} } catch (Exception e1) {NotifyUtils.notifyUser(null, 'error', NotificationType.ERROR);e1.printStackTrace(); } finally {release(connection, statement, resultSet); } return new Rs(r);}public static ResultSet es(String sql) { Connection connection; Statement statement; ResultSet resultSet = null; try {connection = Mysql.DatabaseUtils.getConnection();statement = connection.createStatement();resultSet = statement.executeQuery(sql); } catch (Exception e1) {NotifyUtils.notifyUser(null, 'error', NotificationType.ERROR);e1.printStackTrace(); } return resultSet;}public static void release(Connection connection, Statement st, ResultSet rs) { closeConn(connection); closeRs(rs); closeSt(st);}public static void closeRs(ResultSet rs) { try {if (rs != null) { rs.close();} } catch (SQLException e) {e.printStackTrace(); } finally {rs = null; }}private static void closeSt(Statement st) { try {if (st != null) { st.close();} } catch (SQLException e) {e.printStackTrace(); } finally {st = null; }}private static void closeConn(Connection connection) { try {if (connection != null) { connection.close();} } catch (SQLException e) {e.printStackTrace(); } finally {connection = null; }} } public static class DatabaseUtils {private static Connection connection = null;static { Properties properties = PropertiesUtils.readFromSystem(); try {if (properties != null) { Class.forName('com.mysql.cj.jdbc.Driver'); connection = DriverManager.getConnection( properties.getProperty('mysql.url'), properties.getProperty('mysql.username'), properties.getProperty('mysql.password') ); NotifyUtils.notifyUser(null, '數據庫連接成功', NotificationType.INFORMATION);} } catch (Exception e) {NotifyUtils.notifyUser(null, '數據庫連接失敗', NotificationType.ERROR);e.printStackTrace(); }}public static Connection getConnection() { return connection;} } public static void exec(@NotNull AnActionEvent event, Template template) {StringValue stringValue = new StringValue(template.getDefaultValue());Optional.ofNullable(event.getData(PlatformDataKeys.EDITOR)).ifPresent(editor -> { SelectionModel selectionModel = editor.getSelectionModel(); String selectedText = selectionModel.getSelectedText(); if (StringUtils.isNotBlank(selectedText)) {stringValue.setValue(StrUtil.format(template.getDynamicValue(), selectedText)); }});ClipboardUtils.clipboard(stringValue.getValue());NotifyUtils.notifyUser(event.getProject(), stringValue.getValue(), NotificationType.INFORMATION); } /** * sql 語句模版 */ public enum Template {SELECT('SELECT * FROM x WHERE 1 = 1 AND ', 'SELECT * FROM {} WHERE 1 = 1 AND ', '查詢語句'),UPDATE('UPDATE x SET x = x WHERE 1 = 1 AND ', 'UPDATE {} SET x = x WHERE 1 = 1 AND ', '更新語句'),DELETE('DELETE FROM x WHERE 1 = 1 ', 'DELETE FROM {} WHERE 1 = 1 ', '刪除語句'),INSERT('INSERT INTO * (x) VALUES (x) ', 'INSERT INTO {} (x) VALUES (x) ', '新增語句'),;Template(String defaultValue, String dynamicValue, String describe) { this.defaultValue = defaultValue; this.dynamicValue = dynamicValue; this.describe = describe;}public String getDynamicValue() { return dynamicValue;}public String getDefaultValue() { return defaultValue;}public String getDescribe() { return describe;}/** * 模版內容:默認值 */private final String defaultValue;/** * 動態內容 */private final String dynamicValue;/** * 內容描述 */private final String describe; }}

3、寫個測試連接的類&#xff0c;測試一下 mysql 是否可以正常鏈接

package com.wretchant.fredis.menu.mysql;import com.intellij.notification.NotificationType;import com.intellij.openapi.actionSystem.AnAction;import com.intellij.openapi.actionSystem.AnActionEvent;import com.wretchant.fredis.support.Mysql;import com.wretchant.fredis.util.NotifyUtils;import org.jetbrains.annotations.NotNull;import java.sql.ResultSet;/** * @author Created by 譚健 on 2020/9/15. 星期二. 10:17. * © All Rights Reserved. */public class MysqlConn extends AnAction { @Override public void actionPerformed(@NotNull AnActionEvent event) {try { ResultSet es = Mysql.JDBCUtil.es('select 1 as ct'); es.next(); int ct = es.getInt('ct'); if (ct == 1) {NotifyUtils.notifyUser(null, '連接是正常的', NotificationType.INFORMATION); } else {NotifyUtils.notifyUser(null, '連接不正常', NotificationType.ERROR); } Mysql.JDBCUtil.closeRs(es);} catch (Exception e1) { e1.printStackTrace(); NotifyUtils.notifyUser(null, '連接不正常', NotificationType.ERROR);} }}

IDEA 鏈接Mysql數據庫并執行查詢操作的完整代碼

以上就是IDEA 鏈接Mysql數據庫并執行查詢操作的完整代碼的詳細內容,更多關于IDEA 鏈接Mysql執行查詢操作 的資料請關注好吧啦網其它相關文章!

標簽: MySQL 數據庫
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
亚洲视频二区| 97久久亚洲| 久久91视频| 日本中文字幕不卡| 一二三区精品| 午夜精品福利影院| 综合精品一区| 亚洲精选久久| 亚洲精品欧美| 18国产精品| 国产精品一卡| 久久精品99国产精品日本| 亚洲一区二区三区高清| 一级欧洲+日本+国产| 亚洲成人一区| 亚洲美洲欧洲综合国产一区| 免费精品视频| 日韩欧美中文字幕电影| 日韩不卡在线观看日韩不卡视频| 欧美亚洲综合视频| 国产精品久久久久久久久久久久久久久 | 久久夜夜操妹子| 日本а中文在线天堂| 久久久久国产| 国产精品毛片在线看| 视频在线观看一区二区三区| 亚洲三级观看| 国产欧美88| 国产一区二区三区黄网站| 97人人精品| 欧美在线观看视频一区| 亚洲一区二区三区高清不卡| 在线观看视频免费一区二区三区| 97成人在线| 成人污污视频| 亚洲欧美综合| 亚洲免费网址| 国产日产一区| 日韩成人精品一区| 国产综合精品| 日韩精品一页| 国产一区二区三区精品在线观看| 亚洲91久久| 国产精品美女久久久| 国产视频一区二区在线播放| 国产中文欧美日韩在线| 91精品一区国产高清在线gif| 狠狠干综合网| 国产一精品一av一免费爽爽| 精品99在线| 亚洲欧洲一区| 人人爱人人干婷婷丁香亚洲| 日韩欧美1区| 免费人成黄页网站在线一区二区| 欧美亚洲tv| 国产在线不卡一区二区三区| 欧美va亚洲va日韩∨a综合色| 亚洲久久视频| 欧美xxxx中国| 国产视频亚洲| 精品网站999| 亚洲一区中文| 精品黄色一级片| 午夜在线精品| 国产一区2区| 男女男精品视频网| 国产精品4hu.www| 亚洲福利专区| 国产精品一区二区精品 | 啪啪国产精品| 欧美有码在线| 在线日韩一区| 国产精品亚洲欧美日韩一区在线| 久久蜜桃精品| 国产精品毛片久久久| 狠狠色狠狠色综合日日tαg| 欧美91在线| 亚洲少妇在线| 久久午夜影院| 亚洲色图综合| 日韩精品一卡| 欧美aa在线视频| 在线一区免费观看| 成人国产精品一区二区网站| 五月国产精品| 亚洲精品va| 老司机精品视频网| 亚洲免费毛片| 在线日韩视频| 久久精品五月| 日韩在线黄色| 亚洲免费精品| 性欧美videohd高精| 国产精品成人3p一区二区三区| 好看不卡的中文字幕| 色乱码一区二区三区网站| 日韩国产一二三区| 午夜视频精品| 精品成人免费一区二区在线播放| 日韩1区2区3区| 中日韩男男gay无套| 在线中文字幕播放| 国产精品亚洲产品| 婷婷综合一区| 蜜臀av在线播放一区二区三区| 91精品国产乱码久久久久久久| 久久av导航| 青青草国产成人99久久| 亚洲资源av| 日韩精品不卡一区二区| 久久午夜影院| 国产极品一区| 国产网站在线| 91精品国产福利在线观看麻豆| 日韩国产欧美三级| 日韩av首页| 亚洲日产av中文字幕| 伊人久久亚洲热| 日韩精品诱惑一区?区三区| 欧美1区二区| 国产精品一区二区三区美女| 日韩不卡一区二区| 久久影院一区| 日韩中文影院| 毛片不卡一区二区| 国产精品视频一区二区三区| 欧美日韩夜夜| 欧美日韩午夜电影网| 色8久久久久| 亚洲精品国产日韩| 亚洲三级精品| 日韩精品国产欧美| 日韩av资源网| 亚洲精品第一| 97久久精品| 国产精品一区二区精品| 国产日韩中文在线中文字幕| 欧美精品中文字幕亚洲专区| 亚洲精品三级| 亚洲欧洲国产精品一区| 一区二区国产在线| 亚洲精品黄色| 97se亚洲| 精品国产亚洲日本| 中文一区一区三区高中清不卡免费| 韩国女主播一区二区三区| 中国字幕a在线看韩国电影| 久久国产亚洲| 伊人久久亚洲美女图片| 亚洲一区二区三区无吗| 日本a口亚洲| 精品国产一区二| 99久精品视频在线观看视频| 中文精品在线| 亚洲+小说+欧美+激情+另类| 久久av偷拍| 色婷婷精品视频| 伊人精品久久| 老司机免费视频一区二区| 日韩电影在线视频| 99成人在线| 国产亚洲精品美女久久| 国产a亚洲精品| 久久一区二区中文字幕| 蜜桃一区二区三区| 激情视频网站在线播放色| 国产精品magnet| 久久男人av| 亚洲香蕉网站| 国产农村妇女精品一区二区| 亚洲一区二区三区久久久| 日本中文字幕视频一区| 精品久久国产一区| 国产传媒在线| 亚洲先锋成人| 丝袜脚交一区二区| 久久久精品午夜少妇| 蜜桃av一区二区在线观看| 亚洲免费成人av在线| 久久国产精品免费精品3p | 日韩欧美一区二区三区免费看| jizzjizz中国精品麻豆| 午夜在线精品偷拍| 99视频一区| 日本一区二区三区中文字幕| 欧美国产先锋| 欧美国产91| 日韩高清一区二区| 精品国产亚洲日本| 福利一区在线| 一区二区精品| 久久久精品国产**网站| 91精品一区国产高清在线gif| 伊人久久成人| 精品国产一区二区三区噜噜噜| 日韩精品一区二区三区免费观看| 蜜桃伊人久久| 国产一区二区三区日韩精品| 黄色亚洲大片免费在线观看| 欧美一级网站|