<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-17  評論-64  文章-79  trackbacks-1

    /*
    ?* Copyright 1999-2004 The Apache Software Foundation.
    ?*
    ?* Licensed under the Apache License, Version 2.0 (the "License");
    ?* you may not use this file except in compliance with the License.
    ?* You may obtain a copy of the License at
    ?*
    ?*????? http://www.apache.org/licenses/LICENSE-2.0
    ?*
    ?* Unless required by applicable law or agreed to in writing, software
    ?* distributed under the License is distributed on an "AS IS" BASIS,
    ?* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    ?* See the License for the specific language governing permissions and
    ?* limitations under the License.
    ?*/

    import javax.sql.DataSource;
    import java.sql.Connection;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.SQLException;

    //
    // Here are the dbcp-specific classes.
    // Note that they are only used in the setupDataSource
    // method. In normal use, your classes interact
    // only with the standard JDBC API
    //
    import org.apache.commons.dbcp.BasicDataSource;

    //
    // Here's a simple example of how to use the BasicDataSource.
    // In this example, we'll construct the BasicDataSource manually,
    // but you could also configure it using an external conifguration file.
    //

    //
    // Note that this example is very similiar to the PoolingDriver
    // example.

    //
    // To compile this example, you'll want:
    //? * commons-pool.jar
    //? * commons-dbcp.jar
    //? * j2ee.jar (for the javax.sql classes)
    // in your classpath.
    //
    // To run this example, you'll want:
    //? * commons-collections.jar
    //? * commons-pool.jar
    //? * commons-dbcp.jar
    //? * j2ee.jar (for the javax.sql classes)
    //? * the classes for your (underlying) JDBC driver
    // in your classpath.
    //
    // Invoke the class using two arguments:
    //? * the connect string for your underlying JDBC driver
    //? * the query you'd like to execute
    // You'll also want to ensure your underlying JDBC driver
    // is registered.? You can use the "jdbc.drivers"
    // property to do this.
    //
    // For example:
    //? java -Djdbc.drivers=oracle.jdbc.driver.OracleDriver \
    //?????? -classpath commons-collections.jar:commons-pool.jar:commons-dbcp.jar:j2ee.jar:oracle-jdbc.jar:. \
    //?????? ManualPoolingDataSourceExample
    //?????? "jdbc:oracle:thin:scott/tiger@myhost:1521:mysid"
    //?????? "SELECT * FROM DUAL"
    //
    public class BasicDataSourceExample {

    ??? public static void main(String[] args) {
    ??????? // First we set up the BasicDataSource.
    ??????? // Normally this would be handled auto-magically by
    ??????? // an external configuration, but in this example we'll
    ??????? // do it manually.
    ??????? //
    ??????? System.out.println("Setting up data source.");
    ??????? DataSource dataSource = setupDataSource(args[0]);
    ??????? System.out.println("Done.");

    ??????? //
    ??????? // Now, we can use JDBC DataSource as we normally would.
    ??????? //
    ??????? Connection conn = null;
    ??????? Statement stmt = null;
    ??????? ResultSet rset = null;

    ??????? try {
    ??????????? System.out.println("Creating connection.");
    ??????????? conn = dataSource.getConnection();
    ??????????? System.out.println("Creating statement.");
    ??????????? stmt = conn.createStatement();
    ??????????? System.out.println("Executing statement.");
    ??????????? rset = stmt.executeQuery(args[1]);
    ??????????? System.out.println("Results:");
    ??????????? int numcols = rset.getMetaData().getColumnCount();
    ??????????? while(rset.next()) {
    ??????????????? for(int i=1;i<=numcols;i++) {
    ??????????????????? System.out.print("\t" + rset.getString(i));
    ??????????????? }
    ??????????????? System.out.println("");
    ??????????? }
    ??????? } catch(SQLException e) {
    ??????????? e.printStackTrace();
    ??????? } finally {
    ??????????? try { rset.close(); } catch(Exception e) { }
    ??????????? try { stmt.close(); } catch(Exception e) { }
    ??????????? try { conn.close(); } catch(Exception e) { }
    ??????? }
    ??? }

    ??? public static DataSource setupDataSource(String connectURI) {
    ??????? BasicDataSource ds = new BasicDataSource();
    ??????? ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
    ??????? ds.setUsername("scott");
    ??????? ds.setPassword("tiger");
    ??????? ds.setUrl(connectURI);
    ??????? return ds;
    ??? }

    ??? public static void printDataSourceStats(DataSource ds) throws SQLException {
    ??????? BasicDataSource bds = (BasicDataSource) ds;
    ??????? System.out.println("NumActive: " + bds.getNumActive());
    ??????? System.out.println("NumIdle: " + bds.getNumIdle());
    ??? }

    ??? public static void shutdownDataSource(DataSource ds) throws SQLException {
    ??????? BasicDataSource bds = (BasicDataSource) ds;
    ??????? bds.close();
    ??? }
    }

    posted on 2006-05-18 14:06 飛鳥 閱讀(1165) 評論(1)  編輯  收藏 所屬分類: JAVA

    評論:
    # Linkbuilding 2009-05-18 08:03 | Linkbuilding
    Good afternoon. The radical of one century is the conservative of the next. The radical invents the views. When he has worn them out the conservative adopts them.
    I am from Tome and now study English, give please true I wrote the following sentence: "Search engine optimization optimisation and search engine marketing professional, consulting services for higher search.Seo blog from phoenixrealm - search engine optimisation discussion, seo articles published by hannah in seo with comments."

    With love :-D, Boyden.  回復  更多評論
      
    主站蜘蛛池模板: 免费成人在线电影| 久久亚洲日韩看片无码| 国产zzjjzzjj视频全免费| 欧美最猛性xxxxx免费| 亚洲免费观看在线视频| 蜜桃成人无码区免费视频网站 | 亚洲成人在线网站| 亚洲乱码日产一区三区| 亚洲一区无码精品色| 亚洲精品一级无码鲁丝片| 国产在线19禁免费观看| 四虎影院永久免费观看| 免费A级毛片在线播放不收费| 四虎成人精品在永久免费| 亚洲七七久久精品中文国产| 亚洲人成网站在线观看青青| 国产亚洲精品看片在线观看 | 1000部夫妻午夜免费| 久久精品国产免费观看三人同眠| 曰批全过程免费视频播放网站 | a级特黄毛片免费观看| 免费毛片在线看不用播放器| 日韩视频免费在线观看| 最近免费视频中文字幕大全| 中文字幕影片免费在线观看 | 日本免费久久久久久久网站| 日韩免费无码一区二区三区 | 无码人妻一区二区三区免费视频| 尤物视频在线免费观看| 三级毛片在线免费观看| 亚洲欧美中文日韩视频| 亚洲人成网站在线在线观看 | 亚洲黄色在线观看视频| 伊人久久亚洲综合影院首页| 色婷婷六月亚洲综合香蕉| 一个人看的hd免费视频| 无码国产精品一区二区免费vr| 深夜特黄a级毛片免费播放| 国产在线观看xxxx免费| 在线美女免费观看网站h| 我要看WWW免费看插插视频|