There is always a question, how can Java can connect to SQL Server instance (SQL Server Enterprise Edition does not seem to have this problem, I use the Win2K SQL Server development version, the SQL Server service is turned on, the server is the computer name / SQL form).
This problem can be handled well in .NET, but I haven't figured it out in Java. I finally understood today, I use Microsoft SQL Server 2000 Driver for JDBC.
Microsoft SQL Server 2000 Driver for JDBC SP1 can solve this problem, download address:
http://www.microsoft.com/china/sql/downloads/jdbc_sp1.asp
Import java.sql. *;
PUBLIC CLASS Untitled1 {Public Untitled1 () {}
Public static void main (string [] args) {java.sql.connection con = null; string url = "JDBC: Microsoft: SQLServer: //"; string servername = "Musicispower // SQL"; // Here // In ordinary /, front one is a escape character string portnumber = "1433"; string DatabaseName = "test"; string username = "sa"; string password = "1"; string selectmethod = "cursor"; string connStr = URL serverName ":" portNumber "; databaseName =" databaseName "; selectMethod =" selectMethod ";"; // load the drivers try {DriverManager.registerDriver (new com.microsoft.jdbc.sqlserver SQLServerDriver. ()); Con = DriverManager.getConnection (Connstr, Username, Password); if (conn! = Null) {system.out.print ("conn succ");}}} catch (Exception EX) {EX.PrintStackTrace () }
}