No suitable driver found for jdbc:sqlserver://localhost:1433;DatabaseName=master
解决方案 »
- 邮件编程,必须对各中邮件服务器用不同的sdk么,例如exchange服务器用exchange sdk?
- 请教个关于SQL递归排序的方法
- 在C#版放了几天,居然没人能解答的题目
- 100分求一SQL,急用
- SQL,主从表,关联后 有些数据为空,不知道该如何SELECT,有例子表
- 请问以下几个过程用什么语句可以实现?
- 求助:SQL时间函数:怎样查询上一年度每个月的最后一天!
- 请问如果将一个ID组传给存储过程
- 怯怯的问,sqlserver 有没有触发器,有的话,怎么建
- 请教sqlserver7.0在win2k域服务器上的登陆设置和在独立服务器上的设置有什么不同?
- Log Explorer Error
- sql怪问题 ??
public class helloworld {
public static void main(String[] args) {
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //加载JDBC驱动
String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=test"; //连接服务器和数据库sample
String userName = "sa"; //默认用户名
String userPwd = "47"; //密码
Statement sql;
ResultSet rs;
Connection dbConn;try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!"); //如果连接成功 控制台输出Connection Successful!
} catch (Exception e) {
e.printStackTrace();}}
}
这样是没有错误的
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%Connection con;
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch(ClassNotFoundException e){
out.print(e);
}
try{
con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=master","User=sa","Password=47");
con.close();
out.print("lianjiechenggong");
}
catch(SQLException e){
out.print(e);
}%></body>
</html>出现了上述问题
连接的数据库名应该是‘test’吧
但是我第二次访问的数据库是‘master’
运行结果是这样的
com.microsoft.sqlserver.jdbc.SQLServerException: ???? 1433 ????? localhost ? TCP/IP ???????:?Connection refused: connect???????????? SQL Server ?????????????????? TCP/IP ??????????????????? TCP ?????
不应该是:con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=master","sa","47");吗??