连接数据库成功
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);
谢谢 问题解决了
追答客气了。
已解决 谢谢