我对Java开发很新,我开始学习如何连接到SQL Server。我读过大量的教程,我目前遇到了一个与我的应用程序有关的问题,目前我面临的错误是:JDBC,连接到SQL服务器
没有找到适用于jdbc的驱动程序:sqlserver://192.168.*.***: 1433;数据库= STC
我想知道的是我到底需要对服务器做些什么才能完成连接?请注意,数据库和服务器不在我的桌面上,但位于不同的位置。所有的帮助表示赞赏。
这是我的代码。
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class SecondTest
{
public static void main(String[] argv)
{
System.out.println("-------- MySQL JDBC Connection Testing ------------");
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your MySQL JDBC Driver?");
e.printStackTrace();
return;
}
System.out.println("MySQL JDBC Driver Registered!");
Connection connection = null;
try
{
String url = "jdbc:sqlserver://192.168.***.***:1433;Database=STC";
String username = "*****";
String password = "******";
connection = DriverManager.getConnection(url, username, password);
}
catch (SQLException e)
{
System.out.println("Connection Failed!");
e.printStackTrace();
return;
}
if (connection != null)
{
System.out.println("Fully connected.");
}
else
{
System.out.println("Failed to make connection!");
}
}
}
我认为你是对装载SQLServer的一个错误的驱动程序。尝试使用'Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”);' – 2014-10-07 12:36:23