首页 > 解决方案 > sp_who2 'active' 使用 Java 自动化

问题描述

  1. 我正在尝试在 Microsoft SQL 服务器管理工​​作室中使用 java 执行查询 sp_who2 'active'。
  2. 如果查询成功执行,它将检查数据库上的阻塞情况,如果有任何阻塞,我将收到一封电子邮件通知,其中包含导致阻塞的 SPID。
  3. 到目前为止,我正在尝试像这样连接到数据库:

    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.

我知道我做错了什么,这就是我想要知道的。任何帮助,将不胜感激。我正在尝试但无法真正找到可以解决此问题的解决方案。任何帮助将不胜感激!

标签: javaeclipsejdbcssms

解决方案


推荐阅读