import java.sql.*;
public class MysqlConnect {
public static void main(String[] args) {
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "\\host/context/";
String dbName = "theDatabaseName";
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver ";
String userName = "theUserName";
String password = "thePassword";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url + dbName, userName, password);
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
}
我在运行此代码时遇到问题。尝试连接到SQL Server导致ClassNotFoundException
我已经下载了SQL Server驱动程序(sqljdbc),将它设置在类路径中并将其复制到java/lib目录中,但仍得到相同的结果:ClassNotFoundException
。
任何人都可以帮助我吗?
请具体说明什么是你面临的“问题” ?任何错误/例外/痕迹? – Saket
请提及错误详情。 – Santosh
我已经做出所有适当的变化,由u人说,但仍然得到相同的结果,并得到错误文件没有发现异常 - > java.lang.com.microsoft.sqlserver.jdbc.SQLServerDriver –