java - sp_who2 'active' 使用 Java 自动化
问题描述
- 我正在尝试在 Microsoft SQL 服务器管理工作室中使用 java 执行查询 sp_who2 'active'。
- 如果查询成功执行,它将检查数据库上的阻塞情况,如果有任何阻塞,我将收到一封电子邮件通知,其中包含导致阻塞的 SPID。
到目前为止,我正在尝试像这样连接到数据库:
package database; import java.sql.Connection; import java.sql.DriverManager; public class Main { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub getConnection(); } public static Connection getConnection() throws Exception{ try { String driver = "com.mysql.cj.jdbc.Driver"; String url = "jdbc:sqlserver://myLaptopName//SQLEXPRESS"; String username = "myUserName"; String password = "myPassword"; Class.forName(driver).newInstance(); Connection connect = DriverManager.getConnection(url, username, password); System.out.println(connect); System.out.println("Connected"); return connect; } catch (Exception e) { // TODO: handle exception System.out.println("something is wrong"); e.printStackTrace(); } return null; } }
我在日食中遇到的错误就是这个。
java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception:com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the main URL sections
.
这也是。
Caused by: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the main URL sections.
我知道我做错了什么,这就是我想要知道的。任何帮助,将不胜感激。我正在尝试但无法真正找到可以解决此问题的解决方案。任何帮助将不胜感激!
解决方案
推荐阅读
- r - 使用因素:在 R 中重新排序、重新标记和重新编码
- javascript - 给每个 Popper 自己的 CSS 样式
- ms-access - MS Access中绑定/未绑定表单的问题
- wordpress - 在 woocommerce 商店页面上添加额外的按钮,并使用它来发送产品信息,包括邮件中的图像
- html - React 中的 CSS 不是样式
- javascript - 这个循环什么时候变成假的?分裂只应该导致它
- javascript - 创建受保护的反应路线
- javascript - 找不到模块'@angular/core
- laravel - laravel 6.9 localhost 保持加载比 Not found
- c# - 如果我知道它的名称,如何在动态类中使用属性