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

您的位置:首頁技術(shù)文章
文章詳情頁

IDEA 鏈接Mysql數(shù)據(jù)庫并執(zhí)行查詢操作的完整代碼

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

1、先寫個 Mysql 的鏈接設(shè)置頁面

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數(shù)據(jù)庫并執(zhí)行查詢操作的完整代碼

2、然后簡單的寫個 JDBC 操作數(shù)據(jù)庫的支持類

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 { /** * 執(zhí)行查詢語句的返回結(jié)果 */ 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 {/** * 執(zhí)行sql 并返回 map 數(shù)據(jù) * * @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);// 基礎(chǔ)信息ResultSetMetaData metaData = resultSet.getMetaData();// 返回了多少個字段int columnCount = metaData.getColumnCount();while (resultSet.next()) { Map<String, Object> valueMap = new LinkedHashMap<>(); for (int i = 0; i < columnCount; i++) {// 這個字段是什么數(shù)據(jù)類型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, '數(shù)據(jù)庫連接成功', NotificationType.INFORMATION);} } catch (Exception e) {NotifyUtils.notifyUser(null, '數(shù)據(jù)庫連接失敗', 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;}/** * 模版內(nèi)容:默認(rèn)值 */private final String defaultValue;/** * 動態(tài)內(nèi)容 */private final String dynamicValue;/** * 內(nèi)容描述 */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數(shù)據(jù)庫并執(zhí)行查詢操作的完整代碼

以上就是IDEA 鏈接Mysql數(shù)據(jù)庫并執(zhí)行查詢操作的完整代碼的詳細(xì)內(nèi)容,更多關(guān)于IDEA 鏈接Mysql執(zhí)行查詢操作 的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: MySQL 數(shù)據(jù)庫
相關(guān)文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
日韩国产欧美在线播放| 亚洲香蕉网站| 蜜桃视频一区二区三区在线观看 | 亚洲免费毛片| 日韩精品亚洲一区二区三区免费| 亚洲精品伊人| 国产精品1区| 亚洲最新无码中文字幕久久| av资源新版天堂在线| 久久精品官网| 天堂成人免费av电影一区| 日本免费一区二区视频| 久久爱www.| 久久精品主播| 婷婷亚洲成人| 成年男女免费视频网站不卡| 午夜精品免费| 18国产精品| 日韩久久一区二区三区| 欧美在线综合| 麻豆视频久久| 国产综合婷婷| 日韩精品欧美精品| 精品国产一区二区三区性色av| 亚洲性色av| 亚洲人成网77777色在线播放 | 性欧美精品高清| 国产精品伊人| 日本精品影院| 日韩精品欧美精品| 国产精品精品| 蜜桃av一区二区在线观看| 美日韩一区二区三区| 91精品91| 欧美国产免费| 国产精品毛片一区二区三区| 日本亚洲最大的色成网站www| 久久电影tv| 日韩高清一区在线| 久久久精品网| 美女尤物国产一区| 亚洲视频二区| 久久精品动漫| 欧美激情亚洲| 亚洲tv在线| 久久久精品久久久久久96| 国产伦精品一区二区三区视频| 亚洲黑丝一区二区| 精品视频一二| 日韩国产在线观看一区| 欧美一区二区三区高清视频| 中文无码日韩欧| 激情久久五月| 成人精品久久| 国产精品2023| 日韩中文字幕| 亚洲中字黄色| 久久国产影院| 成人污污视频| 国产精品一区二区三区av麻| 亚洲精品1区2区| 99久久久国产精品美女| 国产精品网在线观看| 蜜桃视频在线观看一区| 美女亚洲一区| 欧美日韩免费看片| 国产精品嫩模av在线| 亚洲日本在线观看视频| 欧美日韩少妇| 91成人网在线观看| 成人va天堂| 极品av在线| 精品午夜视频| 国产精品毛片aⅴ一区二区三区| 在线国产日韩| 久热re这里精品视频在线6| 亚洲午夜黄色| 99精品在线| 久久久9色精品国产一区二区三区| 精品三级av| 久久久久九九精品影院| 日韩av中文字幕一区二区| 亚洲精品人人| 亚洲资源网站| 天堂va欧美ⅴa亚洲va一国产| 丝袜美腿高跟呻吟高潮一区| 午夜日韩av| 欧美日韩三区| 免费日韩av| 久久亚洲风情| 中文字幕成人| 日本一区二区中文字幕| 日韩精品a在线观看91| 在线精品一区二区| 蜜桃久久av一区| 中文字幕日韩高清在线| 亚洲综合国产| 麻豆久久精品| 婷婷成人av| 国产午夜精品一区在线观看| 欧美亚洲一区二区三区| 国产日韩高清一区二区三区在线 | 首页亚洲欧美制服丝腿| 亚洲欧美不卡| 午夜久久av | 99精品视频在线观看免费播放| 中文av在线全新| 啪啪国产精品| 99国产精品99久久久久久粉嫩| 亚洲尤物在线| 啪啪亚洲精品| 美女久久久久久| 亚洲美女久久精品| 国产一区亚洲| 亚洲三级精品| 麻豆精品蜜桃视频网站| 91av亚洲| 丝袜美腿一区二区三区| 97精品资源在线观看| 精品午夜视频| 日韩成人亚洲| 午夜国产一区二区| 日韩精品中文字幕一区二区| 国产精品一区高清| av综合电影网站| 久久aⅴ国产紧身牛仔裤| 日韩高清电影一区| 久久中文字幕一区二区| 欧美/亚洲一区| 亚洲精品人人| 久久精品欧洲| 91成人精品视频| 日本成人精品| 日韩欧美看国产| 日韩中文av| 日韩欧美一区免费| 国产农村妇女精品一二区| 69精品国产久热在线观看| 国产拍在线视频| 综合一区在线| 中文字幕高清在线播放| 亚洲综合精品四区| 麻豆国产一区| 亚洲欧美日韩专区| 美女免费视频一区| 亚洲一区二区三区免费在线观看| 国产欧美一区二区精品久久久 | 黄毛片在线观看| 爽好久久久欧美精品| 另类小说一区二区三区| 一本一本久久| 麻豆国产91在线播放| 日韩视频中文| 精品一区二区三区视频在线播放 | 欧美日韩一区二区国产| 久久久久久久久久久妇女| 日韩av网站在线观看| 99久久精品国产亚洲精品| 国产美女久久| 免费中文字幕日韩欧美| 色偷偷色偷偷色偷偷在线视频| 日韩精品一区二区三区中文在线| 亚洲天堂黄色| 国产精品成人a在线观看| 日韩精品1区2区3区| 欧美成人国产| 国产盗摄——sm在线视频| 日韩精品免费观看视频| 亚洲精品极品少妇16p| 国产精品精品| 久久av电影| 欧美日韩a区| 蜜桃视频一区二区三区 | 成人av三级| 美女久久久久久| 青草综合视频| 模特精品在线| 国产综合婷婷| 久久人人97超碰国产公开结果| 久久精品一区二区国产| 日韩国产欧美三级| 久热re这里精品视频在线6| 亚洲高清毛片| 久久久国产亚洲精品| 成人午夜亚洲| 欧美黄页在线免费观看| 日韩二区三区在线观看| 伊人久久亚洲美女图片| 国产精品原创| 成人在线视频区| 久久影院资源站| 欧美午夜三级| 日韩av一区二区在线影视| 免费在线观看视频一区| 国产亚洲毛片在线| 亚洲在线免费| 视频在线观看国产精品| 亚洲欧美久久久| 亚洲一区二区三区高清不卡| 伊人精品在线|