最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
IDEA链接Mysql数据库并执行查询操作代码
时间:2022-06-29 08:42:52 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下IDEA链接Mysql数据库并执行查询操作代码,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
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 valueMap = dialog.getValueMap(); valueMap.forEach(properties::setProperty); PropertiesUtils.write2System(properties); } } else { NotifyUtils.notifyUser(event.getProject(), "读取配置文件失败,配置文件不存在", NotificationType.ERROR); } } }
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
3、写个测试连接的类,测试一下 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); } } }
相关文章
- 初音未来缤纷舞台兑换码在哪里兑换 兑换码入口介绍 09-18
- 阴阳师雪御前如何配队-雪御前阵容搭配推荐 09-18
- 对决剑之川诸葛玲珑技能及装备如何搭配 09-18
- 顶级弓箭手宝箱怎么获取 09-18
- 嘟嘟脸恶作剧爱丽丝角色如何 09-18
- 鹅鸭杀殡仪员有什么技能 09-18