Java 数据库能连接成功为什么登录失败

连接数据库成功
com.microsoft.sqlserver.jdbc.SQLServerException: 用户 '' 登录失败。 ClientConnectionId:20b2b05b-b2e1-42f9-a86c-f29faafa7bfb

源码
public void actionPerformed(ActionEvent e) {

if (e.getSource() == btn_mesQuery) {

}
if (e.getSource() == btn_ticketQuery) {
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL = "jdbc:sqlserver://localhost:1433;DatabaseName=TicketManager";
String userName = "sa";
String userPwd = "123456";
try
{

Class.forName(driverName);
Connection dbConn = DriverManager.getConnection(dbURL, userName,
userPwd);
System.out.println("连接数据库成功");
}
catch (Exception e1)
{
e1.printStackTrace();
System.out.print("连接失败");
}
Statement stmt = null;
Connection conn = null;
ResultSet rs = null;
try {

conn = DriverManager.getConnection(dbURL);
stmt = conn.createStatement();
String sql = "select *from Ticket where LeaveCity like'";
sql += tf_sStation + "'";
/*and ArriveCity='" + tf_dStation + "';";
sql += "'and LeaveTime="+tf_sTime+"'or TrainID="+tf_trainID+"'";*/
rs = stmt.executeQuery(sql);

看起来,没连接上。有可能是用户名,密码不对。追问

谢谢 问题解决了

追答

客气了。

温馨提示:内容为网友见解,仅供参考
第1个回答  2014-10-24
是不是用户和密码错误,或者没有权限追问

已解决 谢谢

相似回答
大家正在搜