java.sql.SQLException:找不到适用于jdbc:microsoft:

当我尝试运行此程序时,出现此异常。这是微软的例子之一。我已经通过项目属性将sqljdbc4.jar添加到了netbeans的类路径中,以便进行编译和运行。我还测试了可以使用下面的import语句找到该类-编译期间没有错误,因此它必须找到jar。


可能与sqldbc4.jar引用的dll或某些sql dll相关吗?


这是确切的例外,下面是确切的代码(密码除外)。


例外:


run:

java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;databaseName=HealthCareDatabase

Error Trace in getConnection() : No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;databaseName=HealthCareDatabase

Error: No active Connection

    at java.sql.DriverManager.getConnection(DriverManager.java:602)

    at java.sql.DriverManager.getConnection(DriverManager.java:185)

    at javaapplication1.Connect.getConnection(Connect.java:35)

    at javaapplication1.Connect.displayDbProperties(Connect.java:50)

    at javaapplication1.JavaApplication1.main(JavaApplication1.java:23)

BUILD SUCCESSFUL (total time: 1 second)

码:


 package javaapplication1;

import com.microsoft.sqlserver.jdbc.SQLServerDriver;


import java.*;


public class Connect {


    private java.sql.Connection con = null;

    private final String url = "jdbc:microsoft:sqlserver://";

    private final String serverName = "localhost";

    private final String portNumber = "1433";

    private final String databaseName = "HealthCareDatabase";

    private final String userName = "larry";

    private final String password = "xxxxxxx";


    // Constructor

    public Connect() {

    }


    private String getConnectionUrl() {

        return url + serverName + ":" + portNumber + ";databaseName=" + databaseName ;

    }


HUWWW
浏览 866回答 3
3回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

SQL Server