java连接sql2005问题

07-10-27 trbing
用jsp连接sql2005总是不成功!所以写了个java代码测试一下,也不成功!

 import java.sql.*;
import javax.sql.*;
import com.microsoft.sqlserver.jdbc.*;
public class Test{
	public static void main(String args[]){
		String DRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";
	 	String URL1="jdbc:sqlserver://localhost:1433;DatabaseName=db_shopping";
	 	String USER="sa";
	 	String PASSWORD="";
	 	try{
	 		
	 	Class.forName(DRIVER).newInstance();
	 	 	
	 	Connection conn=DriverManager.getConnection(URL1,USER,PASSWORD);
	 	
	 	Statement stmt=conn.createStatement();
	 	
	 	ResultSet rs=stmt.executeQuery("select * from dbo.tab_sex");
	 	
	 	while(rs.next()){
	 		System.out.println(rs.getString("sex"));
	 		}}catch(Exception e){e.printStackTrace();}
	 }
 
 
	}

 
<p>

2005的驱动已经搞定!这个代码总是出错说:com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'sa'. The

user is not associated with a trusted SQL Server connection.

at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError

(Unknown Source)

at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown Source)

at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(Unknown Source

)

at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Sour

ce)

at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)

at java.sql.DriverManager.getConnection(DriverManager.java:525)

at java.sql.DriverManager.getConnection(DriverManager.java:171)

at Test.main(Test.java:14)

高手帮帮忙啊!为什么会Login failed for user 'sa'. ?谢谢!

1
trbing
2007-10-27 20:28
自己顶一下!高手赐教啊!谢谢!

猜你喜欢