JAVA连接SQL2008时,驱动程序已经安装好了,TCP/IP已经开启了,为什么显示用户登录失败?
驱动程序已经安装好了,TCP/IP已经开启了,我用的是WINDOWS登录模式,编译也没有出错,为什么?求高手。。。packageorg.lxh.Connectdemo;i...
驱动程序已经安装好了,TCP/IP已经开启了,我用的是WINDOWS登录模式,编译也没有出错,为什么?求高手。。。
package org.lxh.Connectdemo;
import java.sql.Connection;
import java.sql.DriverManager;
public class jiazai {
public static void main(String[] srg) {
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL = "jdbc:sqlserver://localhost:1433";
String userName = "Administrator";
String userPwd = "";
Connection conn=null;
try {
if(conn==null){
Class.forName(driverName);
conn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!");
}else
return;
} catch (Exception e) {
e.printStackTrace();
System.out.println("Connection Fail!");
}
}
}
******************************
com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'Administrator' 登录失败。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:83)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2532)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:1929)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:1917)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1061)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.lxh.Connectdemo.jiazai.main(jiazai.java:21)
Connection Fail!
*********************************** 展开
package org.lxh.Connectdemo;
import java.sql.Connection;
import java.sql.DriverManager;
public class jiazai {
public static void main(String[] srg) {
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL = "jdbc:sqlserver://localhost:1433";
String userName = "Administrator";
String userPwd = "";
Connection conn=null;
try {
if(conn==null){
Class.forName(driverName);
conn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!");
}else
return;
} catch (Exception e) {
e.printStackTrace();
System.out.println("Connection Fail!");
}
}
}
******************************
com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'Administrator' 登录失败。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:83)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2532)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:1929)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:1917)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1061)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.lxh.Connectdemo.jiazai.main(jiazai.java:21)
Connection Fail!
*********************************** 展开
展开全部
楼主这里写错了
String dbURL = "jdbc:sqlserver://localhost:1433";连数据库名都没有。
附带别的获取数据库连接对象写法:需要加载jtds-1.2.2.jar
Driver driver = (Driver) Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
Properties props = new Properties();
props.setProperty("user", "sa");
props.setProperty("password", "");
String strURL = "jdbc:jtds:sqlserver://192.168.100.1:1433/ct33;tds=8.0";
Connection conn = driver.connect(strURL, props);
String dbURL = "jdbc:sqlserver://localhost:1433";连数据库名都没有。
附带别的获取数据库连接对象写法:需要加载jtds-1.2.2.jar
Driver driver = (Driver) Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
Properties props = new Properties();
props.setProperty("user", "sa");
props.setProperty("password", "");
String strURL = "jdbc:jtds:sqlserver://192.168.100.1:1433/ct33;tds=8.0";
Connection conn = driver.connect(strURL, props);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
核查自己有没有导扩展包,好友用户名密码 还有加载驱动地址 url 我知道2000 与2008的url是不一样的,但是楼主写的好像有点问题
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你没有设置访问数据库,修改代码如下:
String dbURL = "jdbc:sqlserver://localhost:1433;databaseName=dbName";
String dbURL = "jdbc:sqlserver://localhost:1433;databaseName=dbName";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
08的是 String dbURL = "jdbc:sqlserver://localhost:1433;databaseName=?";
“?”是指你要访问的数据库名
顺带一提还得导入sqljdbc2008.jar包,楼主应该有导入的吧
“?”是指你要访问的数据库名
顺带一提还得导入sqljdbc2008.jar包,楼主应该有导入的吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询