试试Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://myhost:1433","uid","password");
当然你得安装微软的SQL Server 2000 JDBC驱动程序,把相应的jar文件们加到classpath上去
总结一下:1.下载Type4的Microsoft SQL Server 2000 JDBC Driver 2.安装驱动,并将目录下的lib文件夹中3个jar包加入ClasPath3.Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");4.Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://myhost:1433","uid","password");
import java.sql.Connection; import java.sql.DriverManager;import java.sql.Statement; import java.sql.ResultSet; public class Selector { public static void main(String[] args) { String url = "jdbc:microsoft:sqlserver://192.168.0.158:1433;DataBaseName=Northwind"; Connection con = null;
http://msdn.microsoft.com/downloads/default.asp?URL=/downloads/sample.asp?url=/MSDN-FILES/027/001/779/msdncompositedoc.xml
2.安装驱动,并将目录下的lib文件夹中3个jar包加入ClasPath3.Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");4.Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://myhost:1433","uid","password");
import java.sql.DriverManager;import java.sql.Statement;
import java.sql.ResultSet;
public class Selector
{
public static void main(String[] args)
{
String url = "jdbc:microsoft:sqlserver://192.168.0.158:1433;DataBaseName=Northwind"; Connection con = null;
try
{
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
Class.forName(driver).newInstance();
}
catch (Exception e)
{
System.out.println("Failed to load Microsoft SQL Server 2000 Driver.");
e.printStackTrace();
return;
}
try
{
con = DriverManager.getConnection(url,"sa","");
Statement select = con.createStatement();
ResultSet result = select.executeQuery("SELECT FirstName,LastName from Employees");
System.out.println("Got results : ");
while(result.next())
{
String firstName;
String lastName;
firstName = result.getString(1);
lastName = result.getString(2);
if(result.wasNull())
{
return;
}
System.out.println("FirstName = "+firstName);
System.out.println("LastName = "+lastName);
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
if (con != null)
{
try
{
con.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
}