在SUN 的网页看了点代码 怎么看怎么看不懂 向各位寻求 java 通过 DataSource 连接数据库的代码 最好是sql server 2000 的 本地只有这个数据库 ,JDBC驱动最好是com.microsoft.jdbc.sqlserver.SQLServerDriver
同时不涉及任何web、C/S B/S应用, 基本上就和常用的drivermange连接本地的那种差不多。区别就是 采用逻辑数据库而不是实际物理数据库的那种
谢谢 !

解决方案 »

  1.   

    用Class.forName方法载入驱动程序
    DriverManager.getConnection获得数据库链接
    调用Connection.createStatement方法创建Statement
    调用Statement.executeQuery、executeUpdate等方法执行语句
    若使用executeQuery,反正的是一个ResultSet,可以对查询结果进行处理
      

  2.   

    这好像不是我要的 
    Establishing a Connection
    First, you need to establish a connection with the DBMS you want to use. Typically, a JDBC™ application connects to a target data source using one of two mechanisms: DriverManager:   This fully implemented class requires an application to load a specific driver, using a hardcoded URL. As part of its initialization, the DriverManager class attempts to load the driver classes referenced in the jdbc.drivers system property. This allows you to customize the JDBC Drivers used by your applications. DataSource:   This interface is preferred over DriverManager because it allows details about the underlying data source to be transparent to your application. A DataSource object's properties are set so that it represents a particular data source.我想要后者的代码 还请大家帮忙 
    或者是不是单机环境下 不能用后者? 谢谢
      

  3.   

    private static BasicDataSource ds = null; public static BasicDataSource getDataSource() {
    if (ds == null) {
    ds = new BasicDataSource(); ds
    .setDriverClassName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    ds
    .setUrl("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=phscard");
    ds.setUsername("sa");
    ds.setPassword("123"); ds.setMaxActive(50);
    }
    }
    return ds;
    }