吧getConnection("jdbc:microsoft:sqlserver://localhost:1433","用户名","密码");
这是sql的定位就是把localhost变成远程主机的ip地址就可以了

解决方案 »

  1.   

    1.首先你得装个JDBC驱动程序,这你可以到MICROSOFT网站下载;
    2.把你下载的驱动程序解压,把三个文件放入到你的classpath中:msbase.jar,mssqlserver.jar,msutil.jar
    3.程序:例子
      import java.sql.*;
      class SqlTest{
          public static void main(String args[]) throws ClassNotFoundException,SQLException{
          String dburl="jdbc:microsoft:sqlserver://计算机IP:数据库端口;DatabaseName=数据库名";  
          String user="sa";
          String password=""; //连接数据库的参数
      String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver"; //连接数据库的驱动程序
      try{
           Class.forName(driver);   //装载数据库驱动程序
           Connection c=DriverManager.getConnection(dburl,user,password);  //得到与数据库连接
           Statement s=c.createStatement(); //创建语句
           ResultSet r=s.executeQuery("SELECT * FORM 表名");//查询数据库
           while(r.next())
               System.out.println(r.getString(1))  //输出数据第一个字段内容
         }catch(ClassNotFoundException e){
           System.out.println("驱动程序装载失败");
           e.printStackTrace();
         }catch(SQLException e){
           System.out.println("与数据库连接失败");
           e.printStackTrace();
         }
       }
    }
    如果你的程序输出 "驱动程序装载失败",那就表示你的驱动程序没有配置好
    如果你的程序输出 "与数据库连接失败",表示你的数据库参数没有设好。